How do you determine the owner of a process

  • Thread starter Thread starter Ken Soenen
  • Start date Start date
K

Ken Soenen

I can get all the processes on the local machine using "GetProcesses". 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
 
GetProcesses unfortunately doesn't return that piece of information. Here's
a link to another post that shows how:

http://groups.google.com/group/micr...hich+process+wmi+coad&rnum=1#2a6272a9b7ecd77b

Here's the code translated to VB.NET

Imports System.Management

Module Module1

Class Sample_SelectQuery

Public Shared Sub Main()
Dim selectQuery As SelectQuery = New SelectQuery("Win32_Process")
Dim searcher As ManagementObjectSearcher = New
ManagementObjectSearcher(selectQuery)
For Each proc As ManagementObject In searcher.Get
Console.WriteLine(proc("Name").ToString)
Dim s(1) As String
proc.InvokeMethod("GetOwner", CType(s, Object()))
Console.WriteLine(("User: " & (s(1) + ("\\" + s(0)))))
Next
Console.ReadLine()
End Sub
End Class
End Module


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

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

Scott Swigart - MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top