Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I created a Windows Service application in c++. The Service autostart after restarting the PC. I have found that after selecting Shut Down in the Windows menu, the Service doesn't start. The Registry entry in "services" exists and querying it using "sc" indicates that it is installed but the executable isn't running and I can delete the .exe file and still get an indication that the service is installed. What could be the reason for that?

What I have tried:

Using the "autostart" option when the service is created.
I have found that if I install a driver, it always start regardless of how the PC was turned off. As for the service, it always start after a soft reboot so I think it is more of a problem with how Windows proceeds after a hard reboot.
Posted
Updated 26-Aug-18 4:59am
v2
Comments
[no name] 26-Aug-18 13:01pm    
a.) "... can delete the .exe file and still get an indication that the service is installed"
This is very normal, the information about the service is in the registry.
b.) soft reboot vs. hard reboot
Strange. Maybe a dependency which you did not pay attention to it?
Michael Haephrati 26-Aug-18 14:22pm    
I use "sc query <service name>. After a hard reboot, the server appears installed but in a "STOP" state. If I type "sc start <service name>" everything is good. The problem is that it doesn't start.
There are many reports of this problem: https://superuser.com/questions/1026496/automatic-services-doesnt-start-automatically-after-windows-restart

1 solution

One reason maybe that some dlls are missing, but it doesnt sound that way.

You should check that the service has the correct rights to start. Service are running under some special system account, which has administrator rights but isnt the administrator.

For some details you should look into the event log of the system control. The mystic error message should help you to investigate the issue.
 
Share this answer
 
Comments
Michael Haephrati 13-Aug-18 13:57pm    
The service perfectly starts after installation and after a soft reboot, but not after a hard reboot
KarstenK 14-Aug-18 5:03am    
Look in the system event log for details. Can you start it manually in the control panel? You are sure that it isnt a problem in the service?
Michael Haephrati 26-Aug-18 10:57am    
I have found that if I install a driver, it always start regardless of how the PC was turned off. As for the service, it always start after a soft reboot so I think it is more of a problem with how Windows proceeds after a hard reboot.
Dave Kreskowiak 26-Aug-18 11:16am    
Look in the Application event log for an messages about your service. A soft restart should not affect how a service starts at all. I would suspect it's more to do with something your doing in your service that's preventing it from starting.
Michael Haephrati 26-Aug-18 12:58pm    
Thanks Dave, I will take a look.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900