Timer in VBScript

 
This script checks to see if a certain program is running and then checks back every second to see if it is still running.
Once the program finishes it writes out the begining and ending time to a log.
Function isRunning(process)
‘WriteToLog "isRunning", "Looking for process=" & process
Set colProcessList = oWMIService.ExecQuery("Select * from Win32_Process Where Name = """ & process & """" )
isRunning = colProcessList.Count
End Function
 
Sub WriteToLog(strProg, strData)
 strCurrentTime = Now()
 oLogFile.WriteLine(Now() & " | " & strProg & " | " & strData)
End Sub
 
Const wbemFlagReturnImmediately = &h10
Const wbemFlagForwardOnly = &h20
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKLM = &H80000002
Set oWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!rootcimv2")
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oLogFile = oFSO.OpenTextFile("c:tempocsetup.txt", ForAppending, True)
Timeit
Sub Timeit
 If isRunning("ocsetup.exe") Then
  C = 666
  Do Until C = 0
   C = isRunning("ocsetup.exe")
   WScript.Echo "."
   WriteToLog "main","Runing ocsetup.exe"
   WScript.Sleep 1000
  Loop
  WriteToLog "main","Finished Runing ocsetup.exe"
 Else
  WScript.Sleep 1000
  WriteToLog "main","Waiting for ocsetup.exe"
  Timeit
 End If
  
End Sub
Advertisements