如何获取远程Windows服务的状态

时间:2015-06-04 14:25:56

标签: c# winforms

我正在尝试获取远程Windows服务的状态。我使用这样的代码,但没有任何反应。标签没有任何价值。请帮助我!

ConnectionOptions options = new ConnectionOptions();
options.Password = "password";
options.Username = "username";
options.Impersonation = System.Management.ImpersonationLevel.Impersonate;

ManagementScope scope = new ManagementScope("\\\\computer_name\\root\\cimv2", options);
scope.Connect();

ServiceController sc = new ServiceController("service_name", "computer_name");
label1.Text = sc.ServiceName;
label2.Text = sc.Status.ToString();

0 个答案:

没有答案