How do you get a processes username?
http://img89.imageshack.us/img89/2897/omgta6.png
Printable View
How do you get a processes username?
http://img89.imageshack.us/img89/2897/omgta6.png
My initial thought is that you retreive it using the StartInfo.UserName property, but after testing a bit I notice that it returns empty strings...
But you can however retrieve it from the process' EnvironmentVariables:
C# Code:
foreach (System.Diagnostics.Process p in System.Diagnostics.Process.GetProcesses()) { listBox1.Items.Add(p.StartInfo.EnvironmentVariables["username"]); }
hmm, just wondering how do you declare variables in an array with a string key?Quote:
Originally Posted by Atheist
like array["key"]?
EDIT:
Also p.StartInfo.EnvironmentVariables["username"] is the current user not the processes username.
That's not an array. By definition arrays are indexed by ordinal. As the documentation says, the EnvironmentVariables property is type StringDictionary. There are various other types of keyed collections too, including the Dictionary(Of TKey, TValue).Quote:
Originally Posted by high6
The ProcessStartInfo class was never intended to tell you anything about running processes. It is specifically designed to let you specify how to start a new process.
The information you want would have to be retrieved via WMI or PInvoke, although I don't claim to know exactly how.