Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to find the username that a process is running under

How to find the username that a process is running under

Scheduled Pinned Locked Moved C#
comhelptutorialquestionworkspace
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    Darryl Borden
    wrote on last edited by
    #1

    I need to be able to determine what user name a process is running under. I can get the process object by using... Process[] p = Process.GetProcessByName("theprocess"); But I need to know if the process is running under the same user name as the account that the current user is logged in under. I know I can get the user name with Environment.Username, but I need to get the process' user name like Task Manager does. Can anyone help?

    Darryl Borden Principal IT Analyst dborden@eprod.com

    N J 2 Replies Last reply
    0
    • D Darryl Borden

      I need to be able to determine what user name a process is running under. I can get the process object by using... Process[] p = Process.GetProcessByName("theprocess"); But I need to know if the process is running under the same user name as the account that the current user is logged in under. I know I can get the user name with Environment.Username, but I need to get the process' user name like Task Manager does. Can anyone help?

      Darryl Borden Principal IT Analyst dborden@eprod.com

      N Offline
      N Offline
      Nader Elshehabi
      wrote on last edited by
      #2

      Hello

      Process[] p = Process.GetProcessByName("theprocess");
      MessageBox.Show(p.StartInfo.Username);

      Regards

      D 1 Reply Last reply
      0
      • N Nader Elshehabi

        Hello

        Process[] p = Process.GetProcessByName("theprocess");
        MessageBox.Show(p.StartInfo.Username);

        Regards

        D Offline
        D Offline
        Darryl Borden
        wrote on last edited by
        #3

        I found a previous reference to that, but the StartInfo object that comes up in my IDE does not have a "Username" property.

        Darryl Borden Principal IT Analyst dborden@eprod.com

        N 1 Reply Last reply
        0
        • D Darryl Borden

          I found a previous reference to that, but the StartInfo object that comes up in my IDE does not have a "Username" property.

          Darryl Borden Principal IT Analyst dborden@eprod.com

          N Offline
          N Offline
          Nader Elshehabi
          wrote on last edited by
          #4

          Hello ProcessStartInfo.Usename property is available in .net framework 2.0 or later. Probably you're using version 1.1 or 1.0. Upgrade to .Net 2.0 by buying Visual Studio 2005, downloading Visual C# express edition, or downloading .Net 2.0 SDK and using its libraries explicitly. Regards:rose:

          1 Reply Last reply
          0
          • D Darryl Borden

            I need to be able to determine what user name a process is running under. I can get the process object by using... Process[] p = Process.GetProcessByName("theprocess"); But I need to know if the process is running under the same user name as the account that the current user is logged in under. I know I can get the user name with Environment.Username, but I need to get the process' user name like Task Manager does. Can anyone help?

            Darryl Borden Principal IT Analyst dborden@eprod.com

            J Offline
            J Offline
            Jun Du
            wrote on last edited by
            #5

            Use WMI or Windows Management Instrumentation. Build a Management Object on the process under discussion. Call its InvokeMethod() and pass "GetOwner" as the method parameter. This way, you can find the owner of a process.

            Best, Jun

            D 1 Reply Last reply
            0
            • J Jun Du

              Use WMI or Windows Management Instrumentation. Build a Management Object on the process under discussion. Call its InvokeMethod() and pass "GetOwner" as the method parameter. This way, you can find the owner of a process.

              Best, Jun

              D Offline
              D Offline
              Darryl Borden
              wrote on last edited by
              #6

              Thank you - this solution worked great for me. I sincerely appreciate your willingness to answer my question.

              Darryl Borden Principal IT Analyst dborden@eprod.com

              J 1 Reply Last reply
              0
              • D Darryl Borden

                Thank you - this solution worked great for me. I sincerely appreciate your willingness to answer my question.

                Darryl Borden Principal IT Analyst dborden@eprod.com

                J Offline
                J Offline
                Jun Du
                wrote on last edited by
                #7

                You're welcome. Glad my advice was useful.

                Best, Jun

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups