get the username associated with a process

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Director - Minvent

    #1

    get the username associated with a process

    Hi,

    I am trying to get the name of the user which stared a process... similar to
    the user name column in the process list in task manager. I have looked
    through the Process members but am at a loss to find what I require!

    Any help would be greatly appreciated.
    --
    If at first you don't succeed... Hide the evidence that you tried!
  • Patrick Steele [MVP]

    #2
    Re: get the username associated with a process

    In article <4E38DA03-71E4-48AD-B755-90A325C964F3@mi crosoft.com>,
    DirectorMinvent @discussions.mi crosoft.com says...[color=blue]
    > Hi,
    >
    > I am trying to get the name of the user which stared a process... similar to
    > the user name column in the process list in task manager. I have looked
    > through the Process members but am at a loss to find what I require!
    >
    > Any help would be greatly appreciated.[/color]

    You'll have to do some PInvoke with the Win32 API. Here's a C# example
    that shows the calls and process:

    http://tinyurl.com/dtvva

    --
    Patrick Steele
    Microsoft .NET MVP

    Comment

    • Herfried K. Wagner [MVP]

      #3
      Re: get the username associated with a process

      "Director - Minvent" <DirectorMinven t@discussions.m icrosoft.com> schrieb:[color=blue]
      > I am trying to get the name of the user which stared a process... similar
      > to
      > the user name column in the process list in task manager. I have looked
      > through the Process members but am at a loss to find what I require![/color]

      You can utilize the 'Win32_Process' class and its 'GetOwner' method to
      determine domain and user the process is belonging to. The documentation on
      'Win32_Process' contains a VBScript sample on how to do that:

      Platform SDK: Windows Management Instrumentation -- 'Win32_Process'
      <URL:http://msdn.microsoft. com/library/en-us/wmisdk/wmi/win32_process.a sp>

      Samples for VB.NET and C# can be found here:

      <URL:http://www.google.to/groups?q=dotnet +Win32_Process+ GetOwner+-herfried>

      --
      M S Herfried K. Wagner
      M V P <URL:http://dotnet.mvps.org/>
      V B <URL:http://classicvb.org/petition/>

      Comment

      Working...