how to restart the windows service automatically with 5 seconds, if it is stopped manually?
I have a windows service that should run on the client's system 24*7 (local server system). If the client tries to stop the service manually, how do I invoke the service within 5-10 seconds? I have already placed the startup type as automatic. But, this feature works only when the system is restarted.
Only Administrators (and LocalSystem) can start and stop Windows services. So a standard user cannot manually stop a service.
A separate watcher process to detect that a service has stopped would also need to run as an Administrator in order to restart it. Naturally, an Administrator is capable of terminating the watcher process or uninstalling it.
This seems to be a management issue, not a technical one. Administrators of the client system should know that the service should not be manually stopped.
Hi @RLWA32 ,
Do we have any inbuilt program that can start the service if stopped (other than the task scheduler)?
What difference does it make which program is available?
The same Administrator issues remain applicable.
Take a look at Once you give away the farm, you can’t take it back: Recovering from a rogue administrator. The takeaway thought about Administrators -- "Once you let a bad person become an administrator, you have lost the game. It is essential that you give administrator privileges only to people you trust."
Call StartService in your application
@Elanchezhiyan P The sc.exe tool can be used to manage services. See Controlling a Service Using SC. But my previous comments about Administrators are equally applicable to its use.
Sign in to comment
Use NotifyServiceStatusChangeW and re-start it with StartService when you receive SERVICE_NOTIFY_STOPPED
Sign in to comment
0 additional answers
Sort by: Most helpful