【问题标题】:I want to create a hidden form that manipulates some windows processes我想创建一个隐藏的表单来操作一些 Windows 进程
【发布时间】:2016-06-10 16:00:25
【问题描述】:

我想创建一个始终打开的隐藏应用程序,我希望此应用程序检测是否打开了具有特定文本的进程以打开另一个应用程序并将其始终置于顶部。 例如:

 private void Form1_Load(object sender, EventArgs e)
        {
            Hide();
            if (Process.text == "DFT Report Generator")//if the process text is this text for example
              {
                Process.Start("someapp.exe");//start someapp
                someapp.TopMost = true; //set the someapp to be always on top
              }    
            else
            {

            }
        }

我怎样才能做到这一点?

【问题讨论】:

  • 您的意思是要监视窗口标题并查找特定标题?
  • 我的意思是,即使我正在使用进程资源管理器查看所有进程,我似乎也无法在进程中找到这个应用程序“DFT 报告生成器”,所以我正在考虑在它的名称后挂钩。当一个人启动这个应用程序(“DFT 报告生成器”)时,我希望我的应用程序检测到它并打开另一个应用程序,并将这个新打开的应用程序放在它上面并将其设置为类似 TopMost=true;
  • 好的,但是代码没有显示任何迭代正在运行的进程.. 有一个谷歌在通过其他进程窗口运行

标签: c# winforms process


【解决方案1】:

为工作使用正确的工具。
使用windows服务项目模板创建windows服务。

【讨论】:

    【解决方案2】:
    1. 创建一个在后台运行的无窗口表单应用程序。粗略的想法是创建一个 Windows 窗体应用程序并禁用可视属性。

    Program.cs

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            //Application.EnableVisualStyles();
            //Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    

    Form.cs

    public partial class Form1 : Form
    {
        public Form1()
        {
            //InitializeComponent();
        }
    
    
        #region Silent mode
    
        private static Form1 _instance;
    
        /// <summary>
        /// Prevent window getting visible
        /// </summary>
        /// <param name="value"></param>
        protected override void SetVisibleCore(bool value)
        {
            // Prevent window getting visible            
            CreateHandle();
            _instance = this;
    
            //do not show the window
            value = false;
    
            base.SetVisibleCore(value);
        }
    
        #endregion
    
    }
    
    1. 有一个特定时间间隔的定时器触发,浏览正在运行的进程,实现你想做的事情。

      Timer _timer;
      
      public Form1()
      {
          //InitializeComponent();
          _timer = new Timer();
          _timer.Interval = 1000; //ms
          _timer.Elapsed += _timer_Elapsed;
      }
      
      private void _timer_Elapsed(object sender, ElapsedEventArgs e)
      {
          foreach (var process in Process.GetProcesses())
          {
              //compare and perform tasks
          }
      }
      

    【讨论】:

      【解决方案3】:

      这是我使用的方法。 processName 是您尝试查找的进程的名称,newPrecessPath 是您不会运行的进程的路径 如果您不想隐藏您的主要内容,请使用 this.Hide() 您可以在计时器中使用此方法尝试每 x 秒查找一次正在运行的进程。

      private void LookProcess(string processName, string newProcessPath)
              {
                  foreach (var process in Process.GetProcesses())
                  {
                      if (process.ProcessName == processName)
                      {
                          ProcessStartInfo prcinf = new ProcessStartInfo();
                          prcinf.WindowStyle = ProcessWindowStyle.Maximized;
                          prcinf.FileName = newProcessPath;
      
                          Process.Start(prcinfprc);
                      }
                  }
              }
      

      【讨论】:

        猜你喜欢
        • 2012-04-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-10-03
        • 2021-01-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多