I use the following code in a C # WinForms application 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 to my local PC or remote PC. However, the StartService method only works on my local PC when I launch it on a remote PC and I get access to it. In this case, the remote computer is a Windows XP pro machine in the same domain, and the user to whom I run the application has local administrator rights on it.
I am not sure if this is a problem with my code or my rights are not correct.
If this is a permissions issue, please let me know and I will try to ask about ServerFault.
thank
source
share