无法通过VBScript终止Windows 8.1中的进程

时间:2017-11-10 08:51:24

标签: vbscript windows-8.1 wmi

我使用下面的代码来终止应用程序的所有实例,例如记事本。但它没有在Windows 8.1(32位操作系统)中执行。它适用于Windows 7(64位操作系统)和Windows 10(32位操作系统)。有人可以帮我摆脱这个吗?

分析:

它失败了:For Each objProcess In colProcess

即使在下面的代码中引入该行,它也会失败:Set objProcess = GetObject("winmgmts:root\cimv2:Win32_Process")

代码:

Function KillAll1(ProcessName)
    Dim objWMIServicde, colProcess
    Dim strComputer, strList, p
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 
    Set objProcess = GetObject("winmgmts:root\cimv2:Win32_Process")
    Set colProcess = objWMIService.ExecQuery("Select * from Win32_Process Where Name like '" & ProcessName & "'")
    For Each objProcess In colProcess
        objProcess.Terminate             
    Next
End Function

KillAll1("notepad.exe")

0 个答案:

没有答案