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. .NET (Core and Framework)
  4. How to get process's user and domain without WMI

How to get process's user and domain without WMI

Scheduled Pinned Locked Moved .NET (Core and Framework)
csharptutorialquestion
3 Posts 2 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
    Dave Midgley
    wrote on last edited by
    #1

    I am trying to get the user and domain of a running process. I can do it using the WMI, but this has various problems (it's slow, it needs to run wmiprvse.exe). There must be a way of getting this information without using the WMI - does anyone know it? (I'm using C# under .NET2.0, but that should be irrelevant, any answer is going to involve a p-invoke, I'm sure)

    Dave

    M 1 Reply Last reply
    0
    • D Dave Midgley

      I am trying to get the user and domain of a running process. I can do it using the WMI, but this has various problems (it's slow, it needs to run wmiprvse.exe). There must be a way of getting this information without using the WMI - does anyone know it? (I'm using C# under .NET2.0, but that should be irrelevant, any answer is going to involve a p-invoke, I'm sure)

      Dave

      M Offline
      M Offline
      Mike Dimmick
      wrote on last edited by
      #2

      The Windows API calls you will need are: OpenProcess to get a handle to the process (ask for PROCESS_QUERY_INFORMATION rights), OpenProcessToken to get a handle to the process's token (ask for TOKEN_QUERY rights), and GetTokenInformation to get the user account associated with the token (pass TokenUser as the second parameter). That will get you the user's security identifier (SID). You then need to use the LookupAccountSid API to turn that back into a username and domain. You can find sample P/Invoke declarations at www.pinvoke.net[^].

      Stability. What an interesting concept. -- Chris Maunder

      D 1 Reply Last reply
      0
      • M Mike Dimmick

        The Windows API calls you will need are: OpenProcess to get a handle to the process (ask for PROCESS_QUERY_INFORMATION rights), OpenProcessToken to get a handle to the process's token (ask for TOKEN_QUERY rights), and GetTokenInformation to get the user account associated with the token (pass TokenUser as the second parameter). That will get you the user's security identifier (SID). You then need to use the LookupAccountSid API to turn that back into a username and domain. You can find sample P/Invoke declarations at www.pinvoke.net[^].

        Stability. What an interesting concept. -- Chris Maunder

        D Offline
        D Offline
        Dave Midgley
        wrote on last edited by
        #3

        Thanks Mike, that's just what I needed.

        Dave

        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