Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Test to see if a program is open

Status
Not open for further replies.

kdw3

Technical User
Apr 25, 2007
3
US
Hello,

I am looking for a simple vbscript that can test to see if a program is open/running. Does anybody have something like that out there?

Thank you for your time.

Kyle
 
I have looked at that link before and it did not help me. I am looking for someone whom has successfully done this and has some code they are willing to share.

Thank you,
 
This is pretty easy to do. You just bind to the WMI provider and get a collection of processes running on the box. Then you compare their names one by one to the name of the process that you're looking for to see if you get a match.

At this point I'm going to highly recommend that you download Scriptomatic 2.0 from the Microsoft Technet Script Center. This is an invaluable tool for someone learning to script. You can use it to see all of the attributes of the Win32_Process class (the one that you want is .Name most likely). Scriptomatic will write 75% of this script for you.
 
i think this is what you need:
Code:
Option Explicit
Dim objWMIService, objProcess, colProcess
Dim strComputer, strList

strComputer = "."

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _ 
& strComputer & "\root\cimv2") 

Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process WHERE name ='your_program'")

For Each objProcess in colProcess
    strList = strList & objProcess.Name & " is running"                      
Next

msgbox strList
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top