Dim searcher As New ManagementObjectSearcher("//" & machine & "/root/cimv2", "SELECT * FROM Win32_Service WHERE Name='" & ServiceName & "'")
searcher.Scope = Scope
If searcher.Get().Count > 0 Then
For Each queryObj As ManagementObject In searcher.Get()
If queryObj("AcceptStop") Then
queryObj.InvokeMethod("StopService", Nothing)
queryObj.Put()
End If
queryObj.InvokeMethod("StartService", Nothing)
queryObj.Put()
Dim inParams As ManagementBaseObject
inParams = queryObj.GetMethodParameters("ChangeStartMode")
inParams("StartMode") = "Automatic"
queryObj.InvokeMethod("ChangeStartMode", inParams, Nothing)
Next
本文介绍了一段VBScript代码,用于在Windows系统中通过WMI管理指定的服务。该脚本能够停止并重新启动服务,并能更改服务的启动模式为自动。
1万+

被折叠的 条评论
为什么被折叠?



