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

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

问题描述

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

I have this VBScript code to terminate one process

  Const strComputer = "." 
  Dim objWMIService, colProcessList
  Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\" & strComputer & "
ootcimv2")
  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?

推荐答案

我过去使用的方法是使用 PsKill 来自 Microsoft 的 SysInternals.PsKill 可以终止系统进程和任何被锁定的进程.

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 & "
ootcimv2")
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天全站免登陆