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); } }
本文介绍了一种使用C#获取正在运行程序的进程ID的方法,通过调用User32.dll库中的函数GetWindowThreadProcessId和FindWindow,可以实现对指定窗口名(如计算器)的进程ID的获取。
9334

被折叠的 条评论
为什么被折叠?



