views:

606

answers:

2

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?

A: 

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.

DmitryK
A: 

It's been a while since I've used srvany, but I think you may find that srvany will stop an executable that it spawns directly, but not any further. So srvany.exe runs cmd.exe, which runs your app, and when srvany is requested to stop it will make sure cmd.exe stops. Your app is not involved in that transaction.

One way to solve this would be to make srvany call your application directly (which may mean finding out how to map drives from within your app). Or, build your application so it is a service itself.

Greg Hewgill