How to get the PID if you know the Image Name

45 pts.
Tags:
Batch
PID
Product ID
VB.NET 2005 Express Edition
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.

Answer Wiki

Thanks. We'll let you know when a new response is added.

Hello, in <b>VBScript+WMI</b> you can do this with the following code:

<pre>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
</pre>

I hope this helps.

Discuss This Question: 4  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Magnificus
    Thank you! It works PERFECT!
    45 pointsBadges:
    report
  • Luigi10011
    would you happen to know what is the newer Update for this code in Visual Basic 2008? Express Edition
    30 pointsBadges:
    report
  • Luigi10011
    ok never mind i completely forgot that i knew C++, i made a file .EXE to close the file by IMAGENAME, thank you anyways and this is now bookmarked cuase i love how this website does this discussionboard
    30 pointsBadges:
    report
  • Luigi10011
    C++, command you use, for WINDOWS ".EXE" "system("taskkill /IM "yourprogramsname" /F");" /F = Force Quit and you can use CMD type in taskkill /? for more commands underneath taskkill, DOS is the god language, except for JAVA = FUN!
    30 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following