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?

Categories

HOME
testng
cookies
mediawiki
push-notification
dictionary
reserved
sqlite-net-extensions
tizen-web-app
malloc
sharepoint-designer
rubygems
v8
survey
in-app-purchase
directx
paradox
nano-server
circuit
iron-router
decimal
angular-ui
oracle-coherence
nhibernate-envers
visual-composer
autoconf
abi
cloudhub
telerik-reporting
mmap
tibco-mdm
blazemeter
android-widget
entitlements
opentype
srcset
contact-form
file-format
dynamics-crm-2013
uft-api
temporary-files
fedex
ruby-on-rails-3.1
glew
eigenvalue
spring-security-kerberos
password-encryption
s
qcombobox
avconv
rainbowtable
zip4j
blogengine.net
domain-model
colorama
forever
csound
python-cryptography
instant
multi-level
underscore.js-templating
google-web-starter-kit
etsy
bstr
prettytensor
actionbardrawertoggle
essence
yaws
ios4
ford-fulkerson
endeca-workbench
citrus-pay
cakephp-3.1
sankey-diagram
jsapi
nstableviewcell
codeigniter-url
gui-test-framework
castle
sgen
aapt
algebraic-data-types
ivyde
jsctypes
cdc
odata4j
bulkloader
ora-00911
eclipse-memory-analyzer
buster.js
gridcontrol
html4
jquery-mobile-dialog
pygit2
armcc
punbb
netdna-api
mercurial-server
visitor-statistic
createwindow
sef
eqatec
avatar
yagni
thread-local-storage
mdac
dbisam
wsdl.exe
ajax-forms

Resources

Encrypt Message