tags:

views:

1729

answers:

2

How can I find the owner of a given process in C#? The class System.Diagnostics.Process doesn't seem to have any properties or methods that will get me this information. I figure it must be available because it is shown in the Windows Task Manager under the "User Name" column.

My specific scenario involves finding the instance of a process (such as taskhost.exe) which is running as "Local Service". I know how to find all the instances of taskhost using

Process.GetProcessesByName("taskhost")

So now I just need to know how to identify the one which is running as local service.

A: 

You can use the Handle property on the process and pass it to GetSecurityInfo through the P/Invoke layer to get the security information on the process.

It's the same as this question:

http://stackoverflow.com/questions/559356/how-do-i-get-the-sid-session-of-an-arbitrary-process

casperOne
A: 

Might want to try the code at this link

First result in google search for "C# get process owner"

Most likely the task manager uses the Win32 API via C to do this. That process is also outlined in the link above.

Eric Petroelje