【问题标题】:Kill a VBScript from another VBScript从另一个 VBScript 中杀死一个 VBScript
【发布时间】:2014-03-11 11:51:19
【问题描述】:

有没有办法从另一个 VBScript(不是从当前执行的 wscript)中杀死 wscript.exe(vb 脚本的 Windows 进程)?

如果我创建这样的脚本:

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

这不会杀死以前的脚本,而是会杀死自己。

【问题讨论】:

  • 知道了。运行 "taskkill.exe /F /IM wscript.exe /T" 就可以了 :)
  • 如果您需要提供澄清/附加信息,请编辑您的问题。这次我冒昧为你做了。
  • taskkill.exe /F /IM wscript.exe /T 将杀死 所有 wscript.exe 进程,包括它自己的父进程。

标签: windows vbscript


【解决方案1】:

我建议使用 WMI 来选择和终止进程。像这样的东西应该可以工作:

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

【讨论】:

    【解决方案2】:
    Option Explicit
    
    Dim strScriptToKill
        strScriptToKill = "ItIsDead.vbs"
    
    Dim objWMIService, objProcess, colProcess
    
        Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
        Set colProcess = objWMIService.ExecQuery ( _ 
            "Select * from Win32_Process " & _ 
            "WHERE (Name = 'cscript.exe' OR Name = 'wscript.exe') " & _ 
            "AND Commandline LIKE '%"& strScriptToKill &"%'" _ 
        )
        For Each objProcess in colProcess
            objProcess.Terminate()
        Next
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-03-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-13
      • 1970-01-01
      相关资源
      最近更新 更多