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
Need assistance with if/then or subroutine
Moderators: Dorian (MJT support), JRL
Need assistance with if/then or subroutine
Randy Bass
Dallas, Texas
Dallas, Texas