Advertisement
damo2233

Launch process after delay if not running

Mar 20th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Dim procName, procPath, waitSeconds
  2.  
  3. procPath = "%WINDIR%\System32\"
  4. procName = "Notepad.exe"
  5. waitSeconds = 30
  6.  
  7. WScript.Sleep waitSeconds*1000
  8. sComputerName = "."
  9. Set objWMIService = GetObject("winmgmts:\\" & sComputerName & "\root\cimv2")
  10. sQuery = "SELECT * FROM Win32_Process"
  11. Set objItems = objWMIService.ExecQuery(sQuery)
  12. 'iterate all item(s)
  13. Dim procRunning
  14. procRunning = False
  15. For Each objItem In objItems
  16.   If objItem.Name = procName Then
  17.      procRunning = True
  18.   End If
  19.    'WScript.Echo "Process [Name:" & objItem.Name & "]"
  20. Next
  21.  
  22. If procRunning = False Then
  23.    CreateObject("WScript.Shell").Run "%comspec% /c start """" """ & procPath & procName & """", 0, True
  24. End If
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement