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)
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
  WriteToLog "main","Finished Runing ocsetup.exe"
  WScript.Sleep 1000
  WriteToLog "main","Waiting for ocsetup.exe"
 End If
End Sub

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s