Click here to Skip to main content
16,006,341 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear Friends,

Here i want to Know how can we stop the windows service when system reboot.Is there any Information please share with me.



Regards,


AnilKumar.D
Posted
Comments
Logi Guna 18-Feb-13 0:37am    
Handle SessionEnded event (described in Sergey Alexandrovich answer), and to stop service, you can use:
System.Diagnostics.Process.Start("sc", "stop " + "serviceName");
Sergey Alexandrovich Kryukov 18-Feb-13 1:01am    
No, unfortunately, this is wrong way to start a service. This way, it won't be started as service. You can make a service auto, to auto-start when the system is loaded.
—SA
Zoltán Zörgő 18-Feb-13 0:50am    
Actually OS should try to stop all services on reboot - and OnShutdown is called, if exists. So I am not sure I understand what you want. By the way SessionEnded occurs on user logoff also, and I ad this can lead to interesting results when this application runs on a server.
Sergey Alexandrovich Kryukov 18-Feb-13 1:03am    
Of course this even should be filtered by Reason:
http://msdn.microsoft.com/en-us/library/microsoft.win32.sessionendedeventargs.reason.aspx
http://msdn.microsoft.com/en-us/library/microsoft.win32.sessionendreasons.aspx

But of course you are right about OnShutdown...
—SA

You need to use native APIs to change the startup type.. More details here http://peterkellyonline.blogspot.com/2011/04/configuring-windows-service.html[^]

BTW why don't you make the startup type as 'Manual' . It will stop on reboot and will wait till it is manually started ?
 
Share this answer
 
In Run type services.msc --> press enter -> got to your Services in the displayed services and right click --> properties --> StartUpType set as Manual. Then You have to start your services manually when ever your system reboots
 
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