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. Process Owner and Parent

Process Owner and Parent

Scheduled Pinned Locked Moved C#
tutorial
3 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.
  • J Offline
    J Offline
    jparsons
    wrote on last edited by
    #1

    I know I'm missing something obvious. I'm writing a tool that does some dianostics on processes. I can't seem to figure out how to locate the name of the user running a process or the id of the parent process. Can someone please point me in the correct direction. Thanks Jared jparsons@jparsons.org www.prism.gatech.edu/~gte477n

    H J 2 Replies Last reply
    0
    • J jparsons

      I know I'm missing something obvious. I'm writing a tool that does some dianostics on processes. I can't seem to figure out how to locate the name of the user running a process or the id of the parent process. Can someone please point me in the correct direction. Thanks Jared jparsons@jparsons.org www.prism.gatech.edu/~gte477n

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      One way ( without digging into the debugging APIs :eek: ) is to P/Invoke the native functions in the following order: OpenProcessToken, GetTokenInformation, then LookupAccountName. You pass Process.Handle to OpenProcessToken to get an access token. You then get a TOKEN_USER struct by calling GetTokenInformation. Finally, use the SID parameter from TOKEN_USER and call LookupAccountName. This also seems to be partly what taskmgr.exe and tasklist.exe (in Windows XP) are doing. There is actually only tree functions you have to P/Invoke and only a couple structs you have to redefine. I'm sorry that I couldn't find a way to get the parent process ID. In fact, I couldn't find anything common that does on Windows, not to say it isn't possible.

      -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

      1 Reply Last reply
      0
      • J jparsons

        I know I'm missing something obvious. I'm writing a tool that does some dianostics on processes. I can't seem to figure out how to locate the name of the user running a process or the id of the parent process. Can someone please point me in the correct direction. Thanks Jared jparsons@jparsons.org www.prism.gatech.edu/~gte477n

        J Offline
        J Offline
        Jose Fco Bonnin
        wrote on last edited by
        #3

        If WMI is an option for your tool you can get all that information from it. Just take a look to the class "Win32_Process". I remember some nice articles about WMI in codeproject. If you don't find them let me know.

        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