How do you determine the owner of a process

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ken Soenen

    How do you determine the owner of a process

    I can get all the processes on the local machine using "GetProcess es". Now I
    need to know the owner of each of these processes. If the Windows Task
    Manager could talk, I would ask it.!!
    Any help would be appreciated. I still haven't mastered the finer points(if
    there are any) of finding something in VB.NET help. Sometimes it takes me
    days to find even something simple.

    thanks,
    ken


  • Scott Swigart

    #2
    RE: How do you determine the owner of a process

    GetProcesses unfortunately doesn't return that piece of information. Here's
    a link to another post that shows how:



    Here's the code translated to VB.NET

    Imports System.Manageme nt

    Module Module1

    Class Sample_SelectQu ery

    Public Shared Sub Main()
    Dim selectQuery As SelectQuery = New SelectQuery("Wi n32_Process")
    Dim searcher As ManagementObjec tSearcher = New
    ManagementObjec tSearcher(selec tQuery)
    For Each proc As ManagementObjec t In searcher.Get
    Console.WriteLi ne(proc("Name") .ToString)
    Dim s(1) As String
    proc.InvokeMeth od("GetOwner", CType(s, Object()))
    Console.WriteLi ne(("User: " & (s(1) + ("\\" + s(0)))))
    Next
    Console.ReadLin e()
    End Sub
    End Class
    End Module


    HTH

    "Ken Soenen" wrote:
    [color=blue]
    > I can get all the processes on the local machine using "GetProcess es". Now I
    > need to know the owner of each of these processes. If the Windows Task
    > Manager could talk, I would ask it.!!
    > Any help would be appreciated. I still haven't mastered the finer points(if
    > there are any) of finding something in VB.NET help. Sometimes it takes me
    > days to find even something simple.
    >
    > thanks,
    > ken
    >
    >
    >[/color]

    Comment

    • Ken Soenen

      #3
      Re: How do you determine the owner of a process

      Scott,
      Thanks for the help. For some reason or other it's choking on the
      "Imports System.Manageme nt" statement. It says: " Namespace or type
      'Management' for the Imports 'System.Managem ent' cannot be found." And I
      guess since this can't be found, the rest of the program falls apart. Any
      ideas??

      ken


      "Scott Swigart" <scott@swigartc onsulting.com> wrote in message
      news:952C9F7D-A07C-4DEF-9D52-438237BE5AFB@mi crosoft.com...[color=blue]
      > GetProcesses unfortunately doesn't return that piece of information.
      > Here's
      > a link to another post that shows how:
      >
      > http://groups.google.com/group/micro...6272a9b7ecd77b
      >
      > Here's the code translated to VB.NET
      >
      > Imports System.Manageme nt
      >
      > Module Module1
      >
      > Class Sample_SelectQu ery
      >
      > Public Shared Sub Main()
      > Dim selectQuery As SelectQuery = New
      > SelectQuery("Wi n32_Process")
      > Dim searcher As ManagementObjec tSearcher = New
      > ManagementObjec tSearcher(selec tQuery)
      > For Each proc As ManagementObjec t In searcher.Get
      > Console.WriteLi ne(proc("Name") .ToString)
      > Dim s(1) As String
      > proc.InvokeMeth od("GetOwner", CType(s, Object()))
      > Console.WriteLi ne(("User: " & (s(1) + ("\\" + s(0)))))
      > Next
      > Console.ReadLin e()
      > End Sub
      > End Class
      > End Module
      >
      >
      > HTH
      >
      > "Ken Soenen" wrote:
      >[color=green]
      >> I can get all the processes on the local machine using "GetProcess es".
      >> Now I
      >> need to know the owner of each of these processes. If the Windows Task
      >> Manager could talk, I would ask it.!!
      >> Any help would be appreciated. I still haven't mastered the finer
      >> points(if
      >> there are any) of finding something in VB.NET help. Sometimes it takes
      >> me
      >> days to find even something simple.
      >>
      >> thanks,
      >> ken
      >>
      >>
      >>[/color][/color]


      Comment

      • Scott Swigart

        #4
        Re: How do you determine the owner of a process

        Sorry. You have to go into the Project | Add reference menu, and add a
        reference to the System.Manageme nt dll.

        Scott Swigart - MVP

        "Ken Soenen" wrote:
        [color=blue]
        > Scott,
        > Thanks for the help. For some reason or other it's choking on the
        > "Imports System.Manageme nt" statement. It says: " Namespace or type
        > 'Management' for the Imports 'System.Managem ent' cannot be found." And I
        > guess since this can't be found, the rest of the program falls apart. Any
        > ideas??
        >
        > ken
        >
        >
        > "Scott Swigart" <scott@swigartc onsulting.com> wrote in message
        > news:952C9F7D-A07C-4DEF-9D52-438237BE5AFB@mi crosoft.com...[color=green]
        > > GetProcesses unfortunately doesn't return that piece of information.
        > > Here's
        > > a link to another post that shows how:
        > >
        > > http://groups.google.com/group/micro...6272a9b7ecd77b
        > >
        > > Here's the code translated to VB.NET
        > >
        > > Imports System.Manageme nt
        > >
        > > Module Module1
        > >
        > > Class Sample_SelectQu ery
        > >
        > > Public Shared Sub Main()
        > > Dim selectQuery As SelectQuery = New
        > > SelectQuery("Wi n32_Process")
        > > Dim searcher As ManagementObjec tSearcher = New
        > > ManagementObjec tSearcher(selec tQuery)
        > > For Each proc As ManagementObjec t In searcher.Get
        > > Console.WriteLi ne(proc("Name") .ToString)
        > > Dim s(1) As String
        > > proc.InvokeMeth od("GetOwner", CType(s, Object()))
        > > Console.WriteLi ne(("User: " & (s(1) + ("\\" + s(0)))))
        > > Next
        > > Console.ReadLin e()
        > > End Sub
        > > End Class
        > > End Module
        > >
        > >
        > > HTH
        > >
        > > "Ken Soenen" wrote:
        > >[color=darkred]
        > >> I can get all the processes on the local machine using "GetProcess es".
        > >> Now I
        > >> need to know the owner of each of these processes. If the Windows Task
        > >> Manager could talk, I would ask it.!!
        > >> Any help would be appreciated. I still haven't mastered the finer
        > >> points(if
        > >> there are any) of finding something in VB.NET help. Sometimes it takes
        > >> me
        > >> days to find even something simple.
        > >>
        > >> thanks,
        > >> ken
        > >>
        > >>
        > >>[/color][/color]
        >
        >
        >[/color]

        Comment

        • Ken Soenen

          #5
          Re: How do you determine the owner of a process

          Thanks. I probably should have known that. It works like a charm!!!!

          ken

          "Scott Swigart" <scott@swigartc onsulting.com> wrote in message
          news:03B49C88-9DC1-485E-A94A-2D27E8D7729C@mi crosoft.com...[color=blue]
          > Sorry. You have to go into the Project | Add reference menu, and add a
          > reference to the System.Manageme nt dll.
          >
          > Scott Swigart - MVP
          >
          > "Ken Soenen" wrote:
          >[color=green]
          >> Scott,
          >> Thanks for the help. For some reason or other it's choking on the
          >> "Imports System.Manageme nt" statement. It says: " Namespace or type
          >> 'Management' for the Imports 'System.Managem ent' cannot be found." And I
          >> guess since this can't be found, the rest of the program falls apart. Any
          >> ideas??
          >>
          >> ken
          >>
          >>
          >> "Scott Swigart" <scott@swigartc onsulting.com> wrote in message
          >> news:952C9F7D-A07C-4DEF-9D52-438237BE5AFB@mi crosoft.com...[color=darkred]
          >> > GetProcesses unfortunately doesn't return that piece of information.
          >> > Here's
          >> > a link to another post that shows how:
          >> >
          >> > http://groups.google.com/group/micro...6272a9b7ecd77b
          >> >
          >> > Here's the code translated to VB.NET
          >> >
          >> > Imports System.Manageme nt
          >> >
          >> > Module Module1
          >> >
          >> > Class Sample_SelectQu ery
          >> >
          >> > Public Shared Sub Main()
          >> > Dim selectQuery As SelectQuery = New
          >> > SelectQuery("Wi n32_Process")
          >> > Dim searcher As ManagementObjec tSearcher = New
          >> > ManagementObjec tSearcher(selec tQuery)
          >> > For Each proc As ManagementObjec t In searcher.Get
          >> > Console.WriteLi ne(proc("Name") .ToString)
          >> > Dim s(1) As String
          >> > proc.InvokeMeth od("GetOwner", CType(s, Object()))
          >> > Console.WriteLi ne(("User: " & (s(1) + ("\\" + s(0)))))
          >> > Next
          >> > Console.ReadLin e()
          >> > End Sub
          >> > End Class
          >> > End Module
          >> >
          >> >
          >> > HTH
          >> >
          >> > "Ken Soenen" wrote:
          >> >
          >> >> I can get all the processes on the local machine using "GetProcess es".
          >> >> Now I
          >> >> need to know the owner of each of these processes. If the Windows Task
          >> >> Manager could talk, I would ask it.!!
          >> >> Any help would be appreciated. I still haven't mastered the finer
          >> >> points(if
          >> >> there are any) of finding something in VB.NET help. Sometimes it
          >> >> takes
          >> >> me
          >> >> days to find even something simple.
          >> >>
          >> >> thanks,
          >> >> ken
          >> >>
          >> >>
          >> >>[/color]
          >>
          >>
          >>[/color][/color]


          Comment

          Working...