无论我尝试使用其中的哪一个,Process.GetProcessById().ProcessName
都会引发异常,说明所有进程都没有运行。
[DllImport("user32.dll", SetLastError = true)]
static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);
[DllImport("user32.dll")]
static extern uint GetWindowThreadProcessId(IntPtr hWnd, IntPtr ProcessId);
for (int x = 0; x < listBox1.Items.Count; x++)
{
IntPtr y = new IntPtr(Convert.ToInt32(listBox1.Items[x].ToString()));
uint processID = 0;
int procID = Convert.ToInt32(GetWindowThreadProcessId(y, out processID));
//int procID = Convert.ToInt32(GetWindowThreadProcessId(y, IntPtr.Zero);
//listBox2.Items.Add(procID);
listBox2.Items.Add(Process.GetProcessById(procID).ProcessName);
}