Question

  Asked: May 16 2008   4:33 PM GMT
  Asked by: Magnificus


How to get the PID if you know the Image Name


VB.NET 2005 Express Edition, Batch, PID, Product ID, Visual Basic 2005

For a program to work I need the PID of an other program, of wich I only know the Image Name.

The reason I need the PID: I want to activate/'bring to front'/focus the other program, to do this I need the PID (or an other way of doing this).

I'm makeing my program with VB.NET 2005 (Express Edition), but the sulotion to activate an other programm, of wich I only know the Image Name, may also be a batch file or somethingelse, as long as my program can (make) it run.

Subscribe to Alerts! Get questions and answers delivered to your Inbox.


E-mail me updates on this question



   SUBSCRIBE

hidden modal window

Answer Wiki (Improve, edit or add to this answer)


 RATE THIS ANSWER
+1
Click to Vote:
  •   1
  •  0



Hello, in VBScript+WMI you can do this with the following code:

Function FindPID(MyProcess)
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
Set colProcessList = objWMIService.ExecQuery("Select * from Win32_Process")
For Each objProcess in colProcessList
If objProcess.Name = MyProcess Then
Result = objProcess.ProcessID
End if
Next
End Function


I hope this helps.
  • AddThis Social Bookmark Button

Browse more Questions and Answers on Development and Microsoft Windows.

Looking for relevant Development Whitepapers? Visit the SearchSQLServer.com Research Library.


Discuss This Answer


You must be logged-in to discuss a question. Log-in/Register

Magnificus  |   May 19 2008  4:14PM GMT

Thank you!
It works PERFECT!