【发布时间】:2021-11-17 21:16:02
【问题描述】:
目前我使用 VBScript 的以下部分来关闭正在运行的进程,效果很好。但管理问题是,如果存在未知进程,脚本不会关闭它。因此,我想将其更改为终止所有正在运行的进程的位置,除非它们被明确排除(因为有一些进程我不想终止)。
Dim WshShell, objShell
Set WshShell = CreateObject("WScript.Shell")
AppList = "iexplore.exe,notepad.exe,wordpad.exe"
'Closing all open applications that are specified in AppList
For Each app In Split(appList, ",")
Set objProcs=GetObject("winmgmts:\\.\root\cimv2").ExecQuery("select * from Win32_Process where Name= '" & app & "'")
For Each process In objProcs
On Error Resume Next
process.Terminate
On Error Goto 0
Next
Next
我看过,但似乎找不到任何东西。而且我可以使用 PowerShell 命令(因为所有 PC 都是 Win10),只要 PS 命令可以完全在此 VBS 内运行,无需维护单独的 PS 文件。
所以这样的事情是可以接受的:
objShell.Run("powershell.exe -switch1 -switch2")
但不是这个:
objShell.Run("powershell.exe c:\scripts\test.ps1")
【问题讨论】: