Skip to content

Process Wait function in VB Script

August 9, 2013

taskwait “rdmc.EXE”

‘:*************************************************
‘: Check for process
‘:=================================================

Function taskwait(ProcName)
Dim WshShell,oWmi,sWmiq,oQResult,oProcess,iRet

Set WshShell = CreateObject(“WScript.Shell”)

Set oWmi = GetObject(“winmgmts:”)
sWmiq = “select * from Win32_Process where name='”& ProcName &”‘”

Set oQResult = oWmi.Execquery(sWmiq)
If oQResult.Count > 0 Then
  For Each oProcess In oQResult
   MySleep 60

  Next
End If

Set WshShell =Nothing
End Function
‘:=============================================================================
‘: Sleep Function
‘:=============================================================================
Function MySleep(seconds)
   wsv = WScript.Version
   if wsv >= “5.1” then
      WScript.Sleep(seconds * 1000)
   else
     elapsed = TimeSerial(0,0,seconds)
     startTime = Time()
     endTime = TimeValue(startTime) + TimeValue(elapsed)
     While endTime > Time()
         ‘
     Wend
   end if
End Function
‘:=============================================================================

Leave a Comment

You comments make us improve. So, please comment