VB.net GetProcesses()

Good Afternoon

I am trying to debug a problem that is occuring when my .exe is running through a Terminal Server.
Problems arise when the .exe is running more than once for a User. Regardless of how that happens, here is what I am interested in doing. I would like to find out if the .exe is running more than once for a
perticular User. I have the following code working to identify if it is running. However, I cannot figure out
how to check by User also.

Dim mgmt As New System.Management.ManagementClass("Win32_Process")
Dim allprocs As System.Management.ManagementObjectCollection
allprocs = mgmt.GetInstances()
For Each Item As Management.ManagementObject In allprocs
Dim str(2) As String
Item.InvokeMethod("GetOwner", str)
MessageBox.Show(str(0))
Next

arghhh had a hard time changing that to VB .net. I have always code with C# :)

Now we are cookin'...I forgot about the Add Reference. Ok, now I am apparently getting the Win32_Process's. However, they are not matching what is in Task Manager. All of the ones
listed for my name are not in the TaskManager and the ones that are in TaskManager for my name
are not in the list.

There is an option in the taskbar which displays processes for all users. If u checked that you should see some extra processes.

I cant understand why processes that are displayed in the taskbar arent visible !!!!

0

Jimbo99999Author Commented: 2007-12-03

surajquptha:

I don't know too much about this. But are the Task Manager Image Names Win32_Processes?
Eveything found for User ed(my name) were not in TaskManager. Also, not one of what is in
TaskManager for ed(my name) was found.

Maybe I am doind something wrong here then...here is my code. I display the message box when the Owner is ed. What do you do to display the Process associated with the Owner? I was trying str(1) or str(2).

Thanks,
jimbo99999

Dim mgmt As New System.Management.ManagementClass("Win32_Process")
Dim allprocs As System.Management.ManagementObjectCollection
allprocs = mgmt.GetInstances()
For Each Item As Management.ManagementObject In allprocs
Dim str(2) As String
Item.InvokeMethod("GetOwner", str)
If str(0) <> "SYSTEM" And str(0) <> "NETWORK SERVICE" And str(0) <> "LOCAL SERVICE" Then
If str(0) = "ed" Then
MessageBox.Show(str(0))
End If
End If
Next

0

Jimbo99999Author Commented: 2007-12-03

surajquptha:

I found the way to get the Image Name for the Item:

Dim ExeName As String = Item.GetPropertyValue("Caption")

Now all I have to do is figure out how to get the UserName of the User executing the .exe so I can use it to check if there is any other one running already for that User.