1

我正在尝试使用以下 VBS 脚本同时关闭多个应用程序,但0x80041017For Each循环行出现错误。它只适用于一个应用程序,但我添加了另一个以终止

strComputer = "."
strProcessToKill1 = "Acrobat.exe" 
strProcessToKill2 = "iexplore.exe" 

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

Set colProcess = objWMIService.ExecQuery _
                ("Select * from Win32_Process Where Name = '" & strProcessToKill1 & "' or '" & strProcessToKill2 & "'")


count = 0
For Each objProcess in colProcess
                objProcess.Terminate()
                count = count + 1
Next 
4

1 回答 1

5

您的 WMI 查询无效,这导致循环失败。您需要为 WHERE 子句的后半部分指定列 (Name)。我也会删除objProcess.Terminate通话的括号。

strComputer = "."
strProcessToKill1 = "Acrobat.exe" 
strProcessToKill2 = "iexplore.exe" 

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

Set colProcess = objWMIService.ExecQuery _
                ("Select * from Win32_Process Where Name = '" & strProcessToKill1 & "' OR Name = '" & strProcessToKill2 & "'")


count = 0
For Each objProcess in colProcess
                objProcess.Terminate
                count = count + 1
Next 
于 2013-04-05T17:27:11.537 回答