I'm using the following code in a C# WinForms app to start windows services on a remote PC
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; }
}
The GetServices method works fine when pointing at my local PC or at the remote PC. The StartService method however only works on my local PC, when run on the remote PC I get access denied. In this case the remote PC is a windows XP pro machine on the same domain and the user I'm running the app under has local admin rights on it.
I'm not sure if this is an issue with my code or if my permissions are not correct.
If this is a permissions issue please let me know and I'll try asking on ServerFault.
Thanks