Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Process User

1,301 views
Skip to first unread message

Noah Coad [MVP .NET/C#]

unread,
Apr 1, 2004, 4:13:20 PM4/1/04
to
Howdy! I need to know what user is using which process on the system.

"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


Willy Denoyette [MVP]

unread,
Apr 1, 2004, 4:37:24 PM4/1/04
to

"Noah Coad [MVP .NET/C#]" <no...@coad.net> wrote in message
news:usu3d4C...@TK2MSFTNGP12.phx.gbl...

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.


Noah Coad [MVP .NET/C#]

unread,
Apr 2, 2004, 2:29:29 AM4/2/04
to
Wow! Now that is a solution from someone who really knows what they're
doing! :)

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...

Willy Denoyette [MVP]

unread,
Apr 2, 2004, 5:07:55 PM4/2/04
to

"Noah Coad [MVP .NET/C#]" <no...@coad.net> wrote in message
news:%23ZHQwQI...@TK2MSFTNGP12.phx.gbl...

> Wow! Now that is a solution from someone who really knows what they're
> doing! :)
>
> Thank you!!
>
> - Noah Coad -
>
> P.S. Will you be at the Global Summitt? I'd like to thank you in person.

Sorry, not this time, thanks anyway.

Willy.


0 new messages