Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

End all WSCRIPT processes!!!

Status
Not open for further replies.

WidowMaker

IS-IT--Management
Jun 30, 2001
12
0
0
DK
Hey,
I have a VBscript which call several other VBscripts. In some of the "Child"-scripts the user have the choice to end the script, but Wscript.Quit only quits the "Child"-script, not the mail "Parent"-script, and the followind scripts are then run....
How do I stop all VBscripts????
 
Hmm.

Well, if you can have the script "call" one script (have it run and finish), then another, then another in sequence... this might work for you:

vbsQuitter.vbs - the "dispatcher" script
Code:
Dim WshShell

Sub AbortOnException(retCode)
	If retCode <> 0 Then
		Wsh.Quit
	End If
End Sub

Set WshShell = Wscript.CreateObject(&quot;Wscript.Shell&quot;)

AbortOnException WshShell.Run(&quot;scr1.vbs&quot;, 1, True)
AbortOnException WshShell.Run(&quot;scr2.vbs&quot;, 1, True)
scr1.vbs - worker script #1
Code:
If MsgBox(&quot;Hi!&quot;, vbOkCancel, &quot;scr1.vbs&quot;) = vbCancel Then
    Wscript.Quit 1
End If
'Normal processing
Wscript.Quit 'Returns 0
scr2.vbs - worker script #2
Code:
If MsgBox(&quot;My turn&quot;, vbOkCancel, &quot;scr2.vbs&quot;) = vbCancel Then
    Wscript.Quit 1
End If
'Normal processing...
Wscript.Quit 'Returns 0

If you click on the Cancel button when scr1.vbs pops up its MsgBox, it will Quit returning a code of 1, causeing vbsQuitter.vbs to Quit itself, thereby not running any additional scripts.
 
I know using WMI you can list all active processes on a machine, but I am not sure you can end processes. It may be worth looking into. Here is a link to some WMI information:


Unfortunetely I do not have time today to explore this any deeper, but I will try to help out more this weekend.

Roger
 
There are some new goodies in WSH 5.6 that let you start processes using WshShell.Exec, which returns a WshScriptExec object that has a Terminate method.

This would let you start a bunch of &quot;satellite&quot; scripts, and if one dies abnormally you might Terminate the others.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top