您的位置:首页 > 编程语言 > C#

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

2016-06-16 22:25 513 查看
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);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: