vbscript
Restart a vbs script if it crashes
I'm trying to make a vb script that will restart another vb script if it crashes. I have searched, and searched but all I get is how to restart a program and since a vb script is a background process it doesn't work when you search in Win32_Process. Here is my code set Service = GetObject ("winmgmts:") set Shell = WScript.CreateObject("WScript.Shell") sEXEName = "Test_To_Block.vbs" while true bRunning = false for each Process in Service.InstancesOf ("Win32_Process") if Process.Name = sEXEName then bRunning=true msgbox("I am active") End If next if bRunning=False then msgbox("I am not active.") Shell.Run sEXEName end if WScript.Sleep(100) wend The problem is that it never see's the file running and just opens hundreds of "Test_To_Stop.vbs"'s which resolves in me having to restart the computer. In my opinion what should be changed is where the code is looking for. for each Process in Service.InstancesOf ("Win32_Process") Instead of looking in "Win32_Process" you need to look in wherever background process' run. I am new to coding so sorry if this is a simple question. Thank you in advance. Regards, A Viper
Probably because the name of the running process is 'wscript.exe' and not 'Test_To_Block.vbs'. You may be able to use the hack mentioned on this page to change the name of the process: If you're running the scripts locally and running some regular scripts, one common hack is just to copy and rename wscript.exe to a particular name, such as "MyScript1.exe". Then run the script with a shortcut as "...\MyScript1.exe MyScript1.vbs". Then the process will show up as MyScript1.exe. Then you can use sEXEName = "MyScript1.exe" Note: instead of using Shell.run sExeName use Shell.run "Test_To_Block.vbs"
Related Links
Output each line of text (+ the first line) to its own .txt file VBS-Script
Handling ADODB connections in classic ASP
How can I maximize, restore, or minimize a window with a vb script?
compare 2 files and copy source if different from destination - vbscript?
How to read an integer from a string in ASP (VB)
Firing a click event using VB Script in windows forms
VBScript to have a local user change password at next logon?
Pass Credentials to WMI Call in VBScript
Writing VB script under HP's QTP-11
VBScript Converting XML Data to an ADODB RecordSet
Matching strings in VBS
ESRI - Arcmap help to create a button that will populate current date for selected features
Visual Basic Script simple time elapsed
VBScript: Appending a word to the MS “Word” 2003 document
Variable scope in VBScript functions
How to customize mass email in Outlook using VBScript?