jcunews

RunOnTerminate.vbs

Jul 2nd, 2019 (edited)
427
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'VBScript to run a process when a specific process (name) is terminated.
  2. 'Requires Administrator rights.
  3. '
  4. 'https://www.reddit.com/user/jcunews1/
  5.  
  6. ProcessNameToWait         = "notepad.exe"
  7. ProcessCmdlineToRun       = """c:\program files\app\app.exe"" /switch"
  8. StopScriptAfterProcessRun = false
  9.  
  10. ProcessNameToWait = ucase(ProcessNameToWait)
  11. set sh = createobject("wscript.shell")
  12. set wmi = getobject("winmgmts:\\.\root\cimv2")
  13. do while true
  14.   set evs = wmi.execnotificationquery("select * from win32_processstoptrace")
  15.   do while true
  16.     set ev = evs.nextevent
  17.     if ucase(ev.processname) = ProcessNameToWait then
  18.       sh.run ProcessCmdlineToRun, 1
  19.       if StopScriptAfterProcessRun then wscript.quit
  20.     end if
  21.   loop
  22. loop
Add Comment
Please, Sign In to add comment