Gav*_*vin 5 c# windows-services
我在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; }
}
Run Code Online (Sandbox Code Playgroud)
指向本地PC或远程PC时,GetServices方法可以正常工作.然而,StartService方法仅适用于我的本地PC,当在远程PC上运行时,我被拒绝访问.在这种情况下,远程PC是同一域上的Windows XP专业版机器,我正在运行该应用程序的用户具有本地管理员权限.
我不确定这是我的代码的问题,还是我的权限不正确.
如果这是权限问题,请告诉我,我会尝试询问ServerFault.
谢谢
事实证明这是一个权限问题。我正在使用虚拟机进行测试,我们的虚拟机对我们的域具有不同的访问权限。
| 归档时间: |
|
| 查看次数: |
9855 次 |
| 最近记录: |