Process.GetProcessById()在所有线程ID /进程ID上抛出ArgumentException“Process Not Running”

时间:2013-02-16 12:00:03

标签: c# exception process pinvoke pid

无论我尝试使用哪一个,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);
            }

0 个答案:

没有答案