How to terminate process using VBScript

前端 未结 2 573
粉色の甜心
粉色の甜心 2020-12-05 15:13

I have this VBScript code to terminate one process

  Const strComputer = \".\" 
  Dim objWMIService, colProcessList
  Set objWMIService = GetObject(\"winmgm         


        
相关标签:
2条回答
  • 2020-12-05 15:42

    The way I have gotten this to work in the past is by using PsKill from Microsoft's SysInternals. PsKill can terminate system processes and any processes that are locked.

    You need to download the executable and place it in the same directory as the script or add it's path in the WshShell.Exec call. Here's your sample code changed to use PsKill.

    Const strComputer = "." 
    Set WshShell = CreateObject("WScript.Shell")
    Dim objWMIService, colProcessList
    Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
    Set colProcessList = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name = 'Process.exe'")
    For Each objProcess in colProcessList 
      WshShell.Exec "PSKill " & objProcess.ProcessId 
    Next
    
    0 讨论(0)
  • 2020-12-05 15:45

    Try explicit assert debug privilege {impersonationLevel=impersonate,(debug)}:

    Set wmi = GetObject("winmgmts:{impersonationLevel=impersonate,(debug)}!\\.\root\CIMV2")
    Set procs = wmi.ExecQuery("SELECT * FROM Win32_Process WHERE Name='SearchIndexer.exe'", , 48)
    For Each proc In procs
        proc.Terminate
    Next
    
    0 讨论(0)
提交回复
热议问题