Advertisement
Guest User

Launch process after delay if not running

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