Pages

Showing posts with label Windows Service. Show all posts
Showing posts with label Windows Service. Show all posts

Tuesday, July 26, 2011

How to start Windows Service on Remote Computer using VB.NET

Dim co As ConnectionOptions = New ConnectionOptions()
'CREDENTIALS
With co

 .Username = "username" 
 .Password = "password"
End With
Dim strComputer As String = "computername"

Dim scope As New System.Management.ManagementScope
scope=New System.Management.ManagementScope("\\" & strComputer & "\root\cimv2", co)
'CONNECT TO THE BOX
scope.Connect()
Dim query As ObjectQuery = New ObjectQuery("Select * from Win32_Service Where Name ='SERVICENAME' ")
Dim searcher As ManagementObjectSearcher = New ManagementObjectSearcher(scope, query)
Dim observer As ManagementOperationObserver = New ManagementOperationObserver()
Dim queryCollection As ManagementObjectCollection=searcher.Get()Dim m As ManagementObject
Dim args As Object
'START THE SERVICE

For Each m In queryCollection
 m.InvokeMethod("StartService", args)
Next