?
Solved

VB.net GetProcesses()

Posted on 2007-12-03
13
Medium Priority
?
1,920 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
[X]
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
  • 7
  • 6
13 Comments
 
LVL 21

Expert Comment

by:surajguptha
ID: 20396045
What operating system are you using?
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 21

Accepted Solution

by:
surajguptha earned 2000 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

764 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