4

I am working on Window 7 and I have multiple desktops by using the Sysinternals Desktops utility. I just want to list all the processes running across all the desktops.

Process[] processlist = Process.GetProcesses();
foreach (Process p in processlist)
{
    listBox1.Items.Add(p.ProcessName + " " + p.Id + " " + p.MainWindowTitle); 
}

With this code I am able to get all the processes running on the current desktop, but I am not able to get the processes running inside different desktops.

Only Desktops is showing as a single process.

How can I get the child processes inside multiple desktops?

4

1 回答 1

2

是的,我明白了..在做 RnD 之后。

我正在使用 user32.dll 和其中一些方法。

如果你也想实现一些东西,使用这些功能。

[DllImport("user32.dll", EntryPoint = "EnumDesktopWindows", ExactSpelling = false, CharSet = CharSet.Auto, SetLastError = true)]
private static extern bool EnumDesktopWindows(IntPtr hDesktop, EnumDelegate lpEnumCallbackFunction, IntPtr lParam);

[DllImport("user32.dll", EntryPoint = "GetWindowText", ExactSpelling = false, CharSet = CharSet.Auto, SetLastError = true)]
private static extern int _GetWindowText(IntPtr hWnd, StringBuilder lpWindowText, int nMaxCount);

[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool IsWindowVisible(IntPtr hWnd);

[DllImport("user32.dll")]
private static extern bool EnumDesktops(IntPtr hwinsta, EnumDesktopProc lpEnumFunc, IntPtr lParam);

[DllImport("user32.dll", SetLastError = true)]
private static extern IntPtr SetActiveWindow(IntPtr hWnd);

[DllImport("user32.dll", SetLastError = false)]
private static extern IntPtr GetDesktopWindow();


[DllImport("user32.dll")]
private static extern IntPtr GetProcessWindowStation();

[DllImport("user32.dll")]
private static extern IntPtr OpenDesktop(string lpszDesktop, uint dwFlags, bool fInherit, uint dwDesiredAccess);

[DllImport("user32.dll")]
private static extern bool SwitchDesktop(IntPtr hDesktop);

通过使用这些方法,我可以列出所有虚拟桌面上的所有正在运行的进程。

于 2013-06-27T12:51:07.733 回答