Reputation: 1574
I'm having a problem with a service not automatically starting on restart right after installation.
I'm creating the service by executing:
sc create MyService binPath= "C:\path to service\MyService.exe" start= auto
After reboot, the service did not start automatically.
However, if I execute:
sc create MyService binPath= "C:\path to service\MyService.exe" start= auto
net start MyService
net stop MyService
and reboot... the service starts... (Same result if don't execute net stop MyService
Why net start ...
have to be called at least once after sc create
for the service to start automatically?
The service have to start AFTER next restart so calling net start
is not an option for me.
Upvotes: 1
Views: 1384
Reputation: 1935
Using the serviceController class to auto start after installation completed worked for me also, but I had a another issue with a windows service not starting automatically. The problem in this instance was that the service was failing silently because it was trying to make an SQL connection before the SQL service had initiated.
Using the Thread.Sleep method put a delay in my Windows service which fixed this issue, so it's always worth checking the services dependencies also.
Upvotes: 0
Reputation: 827
I had a similar issue, but just used the ServiceController class to auto start after installation was completed. My service was only failing to start directly after installation (again with no errors), but after a user logged on or rebooted the service was up and running without issue.
Upvotes: 1