获取Windows后台进程

C# 获取后台进程

using System.Diagnostics;
//遍历电脑中的进程
Process[] processes = Process.GetProcesses();
for (int i = 0; i < processes.GetLength(0); i++)
{
    //我是要找到我需要的YZT.exe的进程,可以根据ProcessName属性判断
    if (processes[i].ProcessName.Equals("YZT"))
    {
         //立即停止关联的进程,建议不要用Close()方法
         processes[i].Kill();
    }
}

C++ 获取后台进程

[DllImport("User32.dll", CharSet = CharSet.Auto)]
 public static extern int GetWindowThreadProcessId(IntPtr hwnd, out int ID);

 [DllImport("user32.dll", EntryPoint = "FindWindow")]
 private extern static IntPtr FindWindow(string lpClassName, string lpWindowName);

 static void Main(string[] args)
 {
      IntPtr hwnd = FindWindow(null, "计算器");
      if (hwnd != IntPtr.Zero)
      {
          int calcID;
          //获取进程ID  
          GetWindowThreadProcessId(hwnd, out calcID);
      }
  }

 

posted @ 2020-12-24 09:54  超级驼鹿  阅读(575)  评论(0编辑  收藏  举报
/*