|
-
Dec 23rd, 2007, 04:24 PM
#1
Thread Starter
Frenzied Member
[2.0] get process username?
How do you get a processes username?
-
Dec 23rd, 2007, 04:55 PM
#2
Re: [2.0] get process username?
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"]);
}
-
Dec 23rd, 2007, 06:54 PM
#3
Thread Starter
Frenzied Member
Re: [2.0] get process username?
 Originally Posted by Atheist
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?
like array["key"]?
EDIT:
Also p.StartInfo.EnvironmentVariables["username"] is the current user not the processes username.
-
Dec 23rd, 2007, 07:07 PM
#4
Re: [2.0] get process username?
 Originally Posted by high6
hmm, just wondering how do you declare variables in an array with a string key?
like array["key"]?
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).
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|