【问题标题】:vbscript- explorer process restored automatically after killvbscript - 资源管理器进程杀死后自动恢复
【发布时间】:2015-09-24 21:39:41
【问题描述】:

我已经多次使用下面的脚本来终止 vbscript 中的进程,没有任何问题。

这一次我试图杀死 explorer.exe。唯一的问题是在我使用脚本在 2 秒内杀死 explorer.exe 后,资源管理器进程恢复。

我不明白?因为如果我使用任务管理器手动终止 explorer.exe,该进程将被终止,直到我再次启动该进程。那么下面的脚本有什么问题呢?

Option Explicit
Dim objWMIService, objProcess, colProcess
Dim strComputer, strProcessKill 
strComputer = "."
strProcessKill = "'explorer.exe'" 

Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" _ 
& strComputer & "\root\cimv2") 

Set colProcess = objWMIService.ExecQuery _
("Select * from Win32_Process Where Name = " & strProcessKill )
For Each objProcess in colProcess
objProcess.Terminate()
Next 

WScript.Quit 

【问题讨论】:

    标签: vbscript process kill wsh


    【解决方案1】:

    一种方式:

    Set oCMD = CreateObject("WScript.Shell")
    oCMD.Run "taskkill /f /im explorer.exe",0,True
    

    【讨论】:

      【解决方案2】:

      你可以这样试试:

      Option Explicit
      Dim objWMIService, objProcess, colProcess
      Dim strComputer, strProcessKill 
      strComputer = "."
      strProcessKill = "'explorer.exe'" 
      
      Set objWMIService = GetObject("winmgmts:" _
      & "{impersonationLevel=impersonate}!\\" _ 
      & strComputer & "\root\cimv2") 
      
      Set colProcess = objWMIService.ExecQuery _
      ("Select * from Win32_Process Where Name = " & strProcessKill )
      For Each objProcess in colProcess
          objProcess.Terminate(1)
      Next 
      

      或者像这样:

      Option Explicit
      Dim Process
      Process = "Explorer.exe"
      Call Kill(Process)
      '****************************************************
      Sub Kill(Process)
          Dim Ws,Command,Execution
          Set Ws = CreateObject("Wscript.Shell")
          Command = "cmd /c Taskkill /F /IM "& Process &""
          Execution = Ws.Run(Command,0,True)
          Set Ws = Nothing
      End Sub 
      '****************************************************
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-01-02
        • 2011-09-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多