Using System; Using System.Management; Namespace ZZ. Wmi { public class Win32servicemanager {private string strpath; Private ManagementClass ManagementClass; Public Win32servicemanager (): This (".", Null,null) { } Public Win32servicemanager (string host,string username,string password) { This.strpath = "////" +host+ "//root//cimv2:win32_service"; This.managementclass = new ManagementClass (strpath); if (username!=null&&username.length>0) { ConnectionOptions connectionoptions = new ConnectionOptions (); Connectionoptions.username = Username; Connectionoptions.password = Password; Managementscope Managementscope = New Managementscope ("////" +host+ "//root//cimv2", connectionoptions); This.managementClass.Scope = Managementscope; } } Verify that you can connect to the remote computer public static bool Remoteconnectvalidate ( String host,string username,string password) { ConnectionOptions connectionoptions = new ConnectionOptions (); Connectionoptions.username = Username; Connectionoptions.password = Password; Managementscope managementscope = new Managementscope ("////" +host+ "//root//cimv2", connectionoptions); Try { Managementscope.connect (); } Catch { } return managementscope.isconnected; } Gets the value of the specified service property public Object Getservicevalue (String servicename,string PropertyName) { ManagementObject mo = This.managementClass.CreateInstance (); Mo. Path = new Managementpath ( This.strpath+ ". name=/"" "+servicename+"/""); return Mo[propertyname]; |