how to restart the windows service automatically with 5 seconds, if it is stopped manually?

Elanchezhiyan P
80
Reputation points
Hi Team,
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.
{count} votes
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