"System.Diagnostics.Process.GetProcesseses" will return an array of
processes, but I need to know if the process returned is owned by the
current user or other users on the system (Windows 2003 Server). How is
this accomplished?
Thanks!
- Noah Coad -
Microsoft MVP
Or you can use the System.Management classes (and WMI), or you can call the
TS API's (WTSEnumerateProcesses and friends) using PInvoke.
Here's how to use the former.
using System.Management;
class Sample_SelectQuery
{
public static void Main() {
SelectQuery selectQuery = new SelectQuery("Win32_Process");
ManagementObjectSearcher searcher =
new ManagementObjectSearcher(selectQuery);
foreach (ManagementObject proc in searcher.Get()) {
Console.WriteLine(proc["Name"].ToString());
//out argument to return user and domain
string[] s = new String[2];
//Invoke the method and populate the array with the user name
and domain
proc.InvokeMethod("GetOwner",(object[])s);
Console.WriteLine("User: " + s[1]+ "\\" + s[0]);
}
}
Willy.
Thank you!!
- Noah Coad -
P.S. Will you be at the Global Summitt? I'd like to thank you in person.
"Willy Denoyette [MVP]" <willy.d...@pandora.be> wrote in message
news:%23hCxsGD...@tk2msftngp13.phx.gbl...
Sorry, not this time, thanks anyway.
Willy.