Sunday, April 3, 2011

How to get the user name or owner of a process in .net

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.

From stackoverflow

0 comments:

Post a Comment