Results 1 to 4 of 4

Thread: [2.0] get process username?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,547

    [2.0] get process username?

    How do you get a processes username?

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    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:
    1. foreach (System.Diagnostics.Process p in System.Diagnostics.Process.GetProcesses())
    2.             {
    3.                 listBox1.Items.Add(p.StartInfo.EnvironmentVariables["username"]);                
    4.             }
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2005
    Posts
    1,547

    Re: [2.0] get process username?

    Quote 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:
    1. foreach (System.Diagnostics.Process p in System.Diagnostics.Process.GetProcesses())
    2.             {
    3.                 listBox1.Items.Add(p.StartInfo.EnvironmentVariables["username"]);                
    4.             }
    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.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] get process username?

    Quote 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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width