0
在我的網絡搜索過程中,我找到了一個應該停止服務的腳本。當前腳本運行,找到在數組中指定的服務,但似乎沒有阻止它們。當腳本輸出服務'State
時,它仍然在運行。以下是腳本。使用VBScript停止多個服務Windows 7
sComputer = "."
aTargetSvcs= Array("mysql","Apache2.4")
Set oWMIService = GetObject("winmgmts:" & "{impersonationlevel=impersonate}!\\" _
& sComputer & "\root\cimv2")
Set cServices = oWMIService.ExecQuery("SELECT * FROM Win32_Service")
For Each oService In cServices
For Each sTargetSvc In aTargetSvcs
If LCase(oService.Name) = LCase(sTargetSvc) Then
If oService.State <> "Stopped" Then
oService.StopService()
Wscript.Echo oService.State
End If
End If
Next
Next
我只是測試它與mysql
和Apache2.4
服務,但是當這個工程,它將與組策略部署到暫時停止了與域修改腳本干擾一些AV服務。
不是我見過的最優雅的劇本。這可能是一個權限問題,您可能沒有權限在腳本運行的上下文中停止服務。 – Lankymart
就是這樣。我在命令行中使用Administrative Privileges運行它,並且它已經停止了這些服務。你是否想把它作爲答案,以便我可以選擇它是正確的? – CaptainQuint