• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 198
  • Last Modified:

Script Which repeatedly check s to see if any specific program is running

i  was looking for a windows script which continuously checks to see if any specific program for example lets say internet explorer is running ..if its not running it runs the program depending on time duration we set in the script.......................i will really appreciate it
0
vagabond1214
Asked:
vagabond1214
  • 3
1 Solution
 
RobSampsonCommented:
Hi there,

A VBScript like this should work.  It runs in an endless loop until you terminate wscript.exe

Regards,

Rob.
strComputer = "."
strApplication = "C:\Windows\System32\Notepad.exe"
intSeconds = 60
strProcess = Mid(strApplication, InStrRev(strApplication, "\") + 1)

Set objShell = CreateObject("Wscript.Shell")
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 

Do
	Set colProcess = objWMIService.ExecQuery ("Select Name from Win32_Process Where Name='" & strProcess & "'")
	boolRunning = False
	For Each objProcess in colProcess
		boolRunning = True
	Next
	If boolRunning = False Then
		objShell.Run strApplication, 1, False
	End If
Loop

Open in new window

0
 
vagabond1214Author Commented:
dio i need to save the file as .vbs or what

i did that way and it gave the following error while opening the file
attachec file showing you about the error msg ..plz see it error msg
0
 
RobSampsonCommented:
You have done it correctly. It is a .vbs file.  The error on line 16 means it cannot the file you specified on the strApplication line.

Change this:
strApplication = "C:\Windows\System32\Notepad.exe"

to an application that you are sure exists, and it should work.

Rob.
0
 
RobSampsonCommented:
It should work with Notepad the way it's written.  I did forget the sleep though...

Rob.

strComputer = "."
strApplication = "C:\Windows\System32\Notepad.exe"
intSeconds = 60
strProcess = Mid(strApplication, InStrRev(strApplication, "\") + 1)

Set objShell = CreateObject("Wscript.Shell")
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 

Do
	Set colProcess = objWMIService.ExecQuery ("Select Name from Win32_Process Where Name='" & strProcess & "'")
	boolRunning = False
	For Each objProcess in colProcess
		boolRunning = True
	Next
	If boolRunning = False Then
		objShell.Run strApplication, 1, False
	End If
	WScript.Sleep intSeconds * 1000
Loop

Open in new window

0

Featured Post

Industry Leaders: 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!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now