The service was on Windows 10, I compiled it with VS2015 and language was C. an exe will be called in the function ServiceMain, it ran normally when I launched service manually and got results as expected from exe. but when I shutdown PC, then started. Service was running automatically, but the exe was not launched, I must launched it manually if I have booted my PC. and the log was gone when the process went into the function ServiceMain. I'm confused thoroughly.
ServiceMain codes as below:
void ServiceMain(int argc, char** argv)
{
int error;
WriteToLog("Service Main");
ServiceStatus.dwServiceType =SERVICE_WIN32;
ServiceStatus.dwCurrentState =SERVICE_START_PENDING;
ServiceStatus.dwControlsAccepted =SERVICE_ACCEPT_STOP
|SERVICE_ACCEPT_SHUTDOWN ;
ServiceStatus.dwWin32ExitCode = 0;
ServiceStatus.dwServiceSpecificExitCode = 0;
ServiceStatus.dwCheckPoint = 0;
ServiceStatus.dwWaitHint = 0;
hStatus = RegisterServiceCtrlHandler(ServiceName,
(LPHANDLER_FUNCTION)ControlHandler);
if (hStatus == (SERVICE_STATUS_HANDLE)0)
{
return;
}
ServiceStatus.dwCurrentState = SERVICE_RUNNING;
SetServiceStatus(hStatus, &ServiceStatus);
installHelper.RunService();
while (ServiceStatus.dwCurrentState == SERVICE_RUNNING)
{
Sleep(SLEEP_TIME);
}
return;
}
The exe is called by installHelper.RunService(). Is there any wrong with these codes? and how should I get exe run automatically on service?
I'm a green hand for the service job. Appreciate for your help in advance!