码迷,mamicode.com
首页 > Windows程序 > 详细

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

时间:2016-06-16 23:21:23      阅读:1385      评论:0      收藏:0      [点我收藏+]

标签:

 [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);
      }
  }

 

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

标签:

原文地址:http://www.cnblogs.com/guwei4037/p/5592334.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!