I have a Windows service being installed with my installer, and then started with the use of ServiceController:
public static int StartService(string serviceName, int timeoutMilliseconds)
{
ServiceController service = new ServiceController(serviceName);
try
{
TimeSpan timeout = TimeSpan.FromMilliseconds(timeoutMilliseconds);
service.Start();
service.WaitForStatus(ServiceControllerStatus.Running, timeout);
service.Close();
return 0;
}
catch
{
return 1;
}
}
The service seems to start just fine, but when the service tries to perform WMI calls to remote computers, it throws an exception;
The RPC server is unavailable. (Exception from HRESULT: 0x800706BA)
I've tried connecting with WBEMTest from the machine the service is running on, to the same machine the service tries to connect to, and it works fine.
Also, if I start the service manually from Services.msc, it works perfectly. What am I missing with ServiceController?