Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows srvany.exe and service STOP

I've read the many answers online on how to use SRVANY.exe to create a Windows service out of anything. My service is a batch file that sets up the environment (i need to set env vars and map drives) and then spawns my c++ app. But when i do a NET STOP, the srvany.exe process goes away, and my c++ app stays alive. Is there any way to have it killed when it receives the stop command? I'd need to be able to bounce it in case of any config file changes.

The reason i picked cmd shell is the easy drive mapping. In theory i can wrap it with either perl or python, whichever is easier to get this behavior, but then i'd need to shell out anyway to map the drives. Does this make sense?

like image 601
Rich Homolka Avatar asked Oct 16 '25 15:10

Rich Homolka


2 Answers

AlwaysUp is a commercial alternative to SrvAny which covers shortcomings like this one in addition to adding more useful features.

NSSM is a open source alternative with slightly fewer features than AlwaysUp but still it can kill the underlying process when you stop the service.

like image 125
Michael Bahig Avatar answered Oct 19 '25 13:10

Michael Bahig


no, srvany was not designed to stop your applications. The main purpose was to be able to start applications as a service that were not designed to run as a service. As a clumsy workaround you can run a scheduled task that will monitor if srvany runs and if not it will terminate your application.

like image 21
DmitryK Avatar answered Oct 19 '25 13:10

DmitryK