I have a C# program that acts as a GUI for a windows service I created. The service can be stopped or started based on a button press from the GUI…a start button press event would call the function below. On my regular pc this code works fine. However, when I place this GUI app on my server it doesn’t start or stop the service. Is there something I am missing or is there a different process for the server services vs regular pc services. I am using Windows Server 2008 R2 and Vista Business…Thanks in advance.
public static bool StartService(string serviceName, int timeoutMilliseconds)
{
ServiceController service = new ServiceController(serviceName);
try
{
TimeSpan timeout = TimeSpan.FromMilliseconds(timeoutMilliseconds);
service.Start();
service.WaitForStatus(ServiceControllerStatus.Running, timeout);
if (service.Status == ServiceControllerStatus.Running)
return true;
else
return false;
}
catch
{
// ...
return false;
}
}
Two things:
First, make sure your try/catch block is logging (or otherwise notifying you) of any exceptions thrown. Also check the servers Event Logs for errors.
Second, check permissions of the account running your program on the server. The account may not have sufficient permissions to stop and start your service while your account on your PC did.