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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking Running Processes

Status
Not open for further replies.

pghTech

Technical User
Jul 19, 2006
37
US
If I create a collection of running processes and I want to check that a process is no longer running, how do I make that check. Below is the collection but I can't figure out how to tack on a condition if the objprocess in the colprocess is no longer running

Code:
strProcess = nameofprocess

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

Set colProcess = objWMIServices.ExecQuery _
("Select * from Win32_Process Where Name = " & strProcess )
For Each objProcess in colProcess
....
....
....
Loop Until(condition that I cant figure out)

Basically I want to do a loop until it finds that the process I specified is no longer running
 
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

Set colRunningServices = objWMIService.ExecQuery("Select * from Win32_Service")

For Each objService in colRunningServices
Wscript.Echo objService.DisplayName & VbTab & objService.State
Next


I hope you find this post helpful.

Regards,

Mark

Check out my scripting solutions at
 
mark,
i think that code will list all the services. i believe the select statement sould be like this:
Select * from Win32_Service Where State = 'Stopped'
 
Have you tried something like this ?
Loop Until colProcess.Count = 0

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
if you are going to do that i would say the very least you should do is take the

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

out of the Do Loop

and put a Wscript.Sleep mmm into the Do Loop so you dont totally kill the machine you are running the script on.

generally for this type of thing i would say a WMI event notification approach would be better...???
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top