我在C WinForms应用程序中使用以下代码在远程PC上启动Windows服务
public static List<Service> GetServices()
{
List<Service> Services = new List<Service>();
ServiceController[] sc = ServiceController.GetServices(Server);
foreach (var s in sc)
{
Services.Add(new Service { Name = s.ServiceName, Running = s.Status == ServiceControllerStatus.Running });
}
return Services;
}
public static bool StartService(string ServiceName)
{
try
{
ServiceController sc = new ServiceController(ServiceName, Server);
sc.Start();
sc.WaitForStatus(ServiceControllerStatus.Running, new TimeSpan(0, 0, 10));
sc.Refresh();
return sc.Status == ServiceControllerStatus.Running;
}
catch(Exception ex) { return false; }
}
当指向本地PC或远程PC时,GetServices方法工作正常。但是,StartService方法仅在本地PC上工作,当在远程PC上运行时,访问被拒绝。在这种情况下,远程PC是同一域中的Windows XP Pro计算机,我运行应用程序的用户对其具有本地管理权限。
我不确定这是我的代码问题还是我的权限不正确。
如果这是权限问题,请通知我,我将尝试在ServerFault上询问。
谢谢