Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VB.net GetProcesses()

Posted on 2007-12-03
13
Medium Priority
?
1,922 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
Technology Partners: 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

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

609 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