By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,170 Members | 1,421 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,170 IT Pros & Developers. It's quick & easy.

Searching the process list

P: n/a
I want to iterate the process list looking at the processes running for the
current user. So I'm using:

foreach (Process p in Process.GetProcesses())
{

}

But I can't see any method or property of the Process object p which tells
me the username of the user running the process. p.StartInfo.UserName always
seems to contain "".

So how can I consider just the processes running under the current user ?

Mar 29 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a

"JezB" <je***********@blueyonder.co.uk> wrote in message
news:%2***************@TK2MSFTNGP10.phx.gbl...
|I want to iterate the process list looking at the processes running for the
| current user. So I'm using:
|
| foreach (Process p in Process.GetProcesses())
| {
|
| }
|
| But I can't see any method or property of the Process object p which tells
| me the username of the user running the process. p.StartInfo.UserName
always
| seems to contain "".
|
| So how can I consider just the processes running under the current user ?
|
You can't use the Process class for this, you will have to use
System.Management and the WMI classes Win32_logonsession and Win32_Process,
or you have to call the Terminal server API's (WTSEnumerateProcesses,
WTSProcessInfo, WTSOpenServer, WTSCloseServer ....) and pass thSID obtained
by WTSProcessInfo to LookupAccountSid using PInvoke.

Willy.
Mar 29 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.