Kasun Lee

Kasun Lee

  • 1.5k
  • 178
  • 13k

Finding the process "Username"

Oct 2 2022 4:46 AM

Hi.


After I get a process using C#, how can i go about finding the "Username" ("SYSTEM" / [user] etc) of that process, as listed in taskmanager?

foreach (Process proc in procs){// proc.(?)}


Or at least the originator of the process -- the System or one of the Users.

 

Thanks.

EDIT: I tried to run my code only if the username is not "SYSTEM" using StartInfo.UserName, but that gives me the exception "Process was not started by this object, so requested information cannot be determined."..


if (proc.StartInfo.UserName != "SYSTEM") // Exception
{
}

Any work-around for that plz?


Answers (1)