Need assistance with if/then or subroutine

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
randybass
Newbie
Posts: 5
Joined: Tue Jun 21, 2005 4:52 pm
Location: Dallas, Texas

Need assistance with if/then or subroutine

Post by randybass » Mon Sep 26, 2005 2:47 am

I am trying to produce an if/then macro or subroutine that sees if a program is running, and if the program is already running, it closes the program and restarts the program. If the program is not running at the specific time it starts the program.

Below is the code I have produced so far: Thanks for your help!!



VBSTART
Sub killProcess(pgm)
set wmi = getobject("winmgmts:")
sQuery = "select * from win32_process " & "where name='" & pgm & "'"
set processes = wmi.execquery(sQuery)
for each process in processes
process.terminate
next
End Sub

Sub StopService(sServiceName)
strComputer = "."
Set wbemServices = GetObject("winmgmts:\\" & strComputer)
sWQL = "Select state from Win32_Service " & "Where displayname='" & sServiceName & "'"
Set oResults = wbemServices.ExecQuery(sWQL)
For Each oService In oResults
If Trim(LCase(oService.State)) = LCase("Running") Then
oService.StopService
End If
Next
End Sub

VBEND
VBRun>KillProcess,WEBGRABIT.EXE
VBRun>StopService





Run>C:\Program Files\WEBGRABIT.EXE
Randy Bass
Dallas, Texas

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts