I am trying to retrieve the user account under which a process has been started. So far i have not found any answers that retrieve the good information. All of them return the string
of the username which is not the account. I have tried WMI and Diagnostic all with the same results which are half correct.
Let's say i start notepad twice.
- First one i open it with the account : \MyDomain\Franck
- Second on i open it with the account : \MyComputer\Franck
Then use either WMI or Diagnostics and both return username "Franck" and i have not way to know if it's running under the local user or the domain one.
One way could be to use Diagnostics
var procs = Process.GetProcessesByName("Notepad").ToList();
var notepad1 = procs[0].StartInfo.Environment["Username"];
var notepad2 = procs[1].StartInfo.Environment["Username"];
Both return Franck
but one is the domain account and the other is the local.