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