Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

VB.net GetProcesses()

Posted on 2007-12-03
13
1,914 Views
Last Modified: 2008-02-01
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.  

Can you help?

Thanks,
jimbo99999

Dim x As Integer = 0
            Dim Ctr As Integer = 0
            Dim som() As System.Diagnostics.Process
            som = System.Diagnostics.Process.GetProcesses()
            Dim Name As String
            For x = 0 To som.Length - 1
                Name = som(x).ProcessName.ToUpper
                If som(x).ProcessName = "Enhance" Then
                    Ctr += 1
                End If
            Next x

0
Comment
Question by:Jimbo99999
  • 7
  • 6
13 Comments
 
LVL 21

Expert Comment

by:surajguptha
ID: 20396045
What operating system are you using?
0
 
LVL 21

Expert Comment

by:surajguptha
ID: 20396071
0
 

Author Comment

by:Jimbo99999
ID: 20396169
surajquptha:

Thanks for the reply.  I found the following in the links you forwarded but I am not sure where I need to put it in my code.  It also appears to be a bit different than my VB.net code.

ManagementClass processInfo = new ManagementClass("Win32_Process");

ManagementObjectCollection processes = processInfo.GetInstances();

foreach (System.Management.ManagementObject process in processes)
{

//arg to send with method invoke to return user and domain

string[] o = new String[2];



//Invoke the method and populate the o var with the user name and domain

process.InvokeMethod("GetOwner", (object[])o);
Debug.WriteLine(o[0]);


}
0
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
LVL 21

Accepted Solution

by:
surajguptha earned 500 total points
ID: 20396378
       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# :)
0
 
LVL 21

Expert Comment

by:surajguptha
ID: 20396384
Make sure u include system.Management in your references
0
 

Author Comment

by:Jimbo99999
ID: 20396574
surajquptha:

Thanks for your return reply.  When I try to import  --> Imports System.   there is no management to select from the list.  What do I do now?

Thanks,
jimbo99999
0
 
LVL 21

Expert Comment

by:surajguptha
ID: 20396751
Goto Add references-> .Net -> Choose system.Management
0
 

Author Comment

by:Jimbo99999
ID: 20396924
surajquptha:

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.  

What do you think?

Thanks,
jimbo99999
0
 
LVL 21

Expert Comment

by:surajguptha
ID: 20397025
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
 

Author Comment

by:Jimbo99999
ID: 20397079
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.

I am perplexed...
jimbo99999
0
 
LVL 21

Expert Comment

by:surajguptha
ID: 20397526
Yes thats right.. Task Manager Image Names are Win32_Processes
0
 

Author Comment

by:Jimbo99999
ID: 20397622
surajquptha:

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
 

Author Comment

by:Jimbo99999
ID: 20397823
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.

Thanks for the help,
jimbo99999

I will make another post for the User help if needed.
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question