如何使用VBScript终止进程 [英] How to terminate process using VBScript

查看:280
本文介绍了如何使用VBScript终止进程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有此VBScript代码来终止一个进程

I have this VBScript code to terminate one process

  Const strComputer = "." 
  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 
    objProcess.Terminate() 
  Next  

它在某些进程中可以正常工作,但是当涉及到任何在SYSTEM下运行的进程时,它无法停止它.

It works fine with some processes, but when it comes to any process runs under SYSTEM, it can't stop it.

我需要添加任何内容以终止SYSTEM下的进程吗?

Is there is anything I need to add to kill the process under SYSTEM?

推荐答案

我过去使此方法起作用的方法是使用

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.

您需要下载可执行文件,并将其放置在与脚本相同的目录中,或者将其路径添加到WshShell.Exec调用中.这是您的示例代码已更改为使用PsKill.

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

这篇关于如何使用VBScript终止进程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆