Kasun Lee

Kasun Lee

  • 1.4k
  • 178
  • 12.7k

Finding the process "Username"

Oct 2 2022 4:46 AM


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.



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)