Loading

C#获取运行程序的进程ID

 C#获取运行程序的进程ID

[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 @ 2016-06-16 22:25  guwei4037  阅读(3981)  评论(0编辑  收藏  举报