Question

I have two VB Scripts, say First.vbs and Second.vbs.

First.vbs calls Second.vbs each time some action/event happens.

I want to write a new VB Script, say Third.vbs, which terminates all the instances of First.vbs and Second.vbs including itself, Third.vbs.

Can anyone give some suggestion/reference?

Was it helpful?

Solution

Try this:

Set wmi = GetObject("winmgmts://./root/cimv2")

Sub TerminateScript(name)
  qry = "SELECT * FROM Win32_Process WHERE CommandLine LIKE '%" & name & "%'"
  For Each p In wmi.ExecQuery(qry)
    p.Terminate
  Next
End Sub

TerminateScript "Second.vbs"
TerminateScript "First.vbs"

WScript.Quit(0)  'terminate self

OTHER TIPS

You can also use the following query:

"SELECT * FROM Win32_Process WHERE CommandLine LIKE '%wscript.exe%'"

Please note this may stop all the processes running in a machine, with the name wscript.exe.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top