1StaticvoidMain (string[] args)2 {3ConnectionOptions op =Newconnectionoptions ();
Remotely logged on to the remote computer,4Op. Username ="Domain\\domainuser";5Op. Password ="Password";6 //the IP address must be "computer name" and cannot be used at this point. Domain name \root\cimv27Managementscope scope =NewManagementscope (@"\\Servername.Domain\root\cimv2", op);8 scope. Connect ();9Managementpath Path =NewManagementpath ("Win32_Service");Ten using(ManagementClass services =NewManagementClass (scope, PATH,NULL)) One { A foreach(ManagementObject ServiceinchServices. GetInstances ()) - { -Console.WriteLine ("{0}:{1}", service. GetPropertyValue ("Name"). ToString (), service. GetPropertyValue (" State"). ToString ()); the } - } - - Console.readkey (); +}
Run the results, sure enough to live up to expectations.
Reference:
1,) Http://www.codeproject.com/Articles/36268/Monitor-and-Manage-Services-on-Remote-Machines
2,) http://www.codeitive.com/0HJgVkjVeq/check-status-of-services-that-run-in-a-remote-computer-using-c.html
C # Accessing the Windows service state of a remote computer