Reputation: 51
I register my program as a windows service. When I reboot the windows, the service will be START_PENDING forever. After I traced, I found it hung on CreateService function.
hService=CreateService( hSCManager,
pszDriverName,
pszDriverName,
SERVICE_ALL_ACCESS,
SERVICE_KERNEL_DRIVER,
SERVICE_DEMAND_START,
SERVICE_ERROR_NORMAL,
pszDriverPath,
NULL,
NULL,
NULL,
NULL,
NULL);
I can resolve the problem by creating the service before rebooting, but I want to know what the hang happened. Does anyone have any idea?
Upvotes: 2
Views: 988
Reputation: 1062
Applications which have services usually have an installer which registers and installs their services. When you install an application , all services are made and registered and there is no need to install them again while booting the system. Windows executes this function as a regular function while starting the service.
The function which you have mentioned above is used for service installation in installers when a new service should be created.
Upvotes: 0
Reputation: 131
If I remember well, services must be created only once. You don't have to call the CreateService function again ever ! And I wouldn't recommend to create it while in the Windows boot process.
As you can see in the following MSDN example, you have to start the given example software with "install" command line argument to create the service. In any other case the service is considered as installed.
Notice in the example the use of StartServiceCtrlDispatcher function to launch the service main function (In this case SvcMain).
http://msdn.microsoft.com/en-us/library/windows/desktop/bb540476(v=vs.85).aspx
Upvotes: 1