Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kill a VBScript from another VBScript

Is there any way to kill a wscript.exe (windows process for vb script) from another VBScript (not from the currently executing wscript)?

If I create a script like this:

Set s = CreateObject("WScript.Shell")
s.Run "taskkill /im wscript.exe", , True

instead of killing the former script, this will kill itself.

like image 506
AKHIL K Avatar asked Jun 19 '26 04:06

AKHIL K


1 Answers

I'd recommend using WMI for selecting and terminating the processes. Something like this should work:

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

qry = "SELECT * FROM Win32_Process WHERE Name='wscript.exe' AND NOT " & _
      "CommandLine LIKE '%" & Replace(WScript.ScriptFullName, "\", "\\") & "%'"

For Each p In wmi.ExecQuery(qry)
  p.Terminate
Next
like image 134
Ansgar Wiechers Avatar answered Jun 20 '26 19:06

Ansgar Wiechers



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!