Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have windows service (developed in c# visual studio 2013 & .net framework 4.5.1).

Windows service is working fine when we install and it run without any issue.

My problem is when I restart my PC windows service is getting stopped but I want my service should automatically start when PC restarted/started.
This problem I'm facing in windows 10, 11 OS and windows server 2022.

In windows server 2012 it is working fine and getting automatically start when PC restarted/started.

In code I have set start type (in installer.cs)
C#
this.serviceInstaller1.StartType = System.ServiceProcess.ServiceStartMode.Automatic;
Please help me to resolve this issue. Thank you in advance

What I have tried:

Tried to set start type in few other class files but did not worked.
Posted
Updated 25-Mar-24 23:14pm
v2
Comments
Pete O'Hanlon 26-Mar-24 7:02am    
Have you checked that the service is still set to auto-start on the server? Setting the start type to Automatic only applies during the registration of the service. This doesn't override someone else changing the value once it has been installed.

Without your service (and probably your actual PC) we can't really tell what is going on - so I'd start by adding logging to the service and reinstall - that way, you should at least be able to tell if the system is trying to start it, and if it does then how far it gets.

Hopefully, that'll give you better information to work with - at the very least you know to look for a system not starting it" type problem or maybe a "resource not available yet" problem instead.
 
Share this answer
 
Open the machines Event Log Viewer and look in the Application event log for any error messages concerning your service.

Without more information and what your code does at startup, and your code, it's impossible for anyone to tell you what's going on.
 
Share this answer
 

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