What is the cleanest, most reliable way to run a Windows application as a service without touching its code?
Use case: NorthScale's 64-bit Windows version of memcached runs as a generic application.开发者_运维问答 I'd like to stick it into a Windows 2003 or 2008 Service so I can start/stop/restart/etc it through the standard interface.
The Windows Resource Kit has any executable, srvany.exe
that can be used, as described here, to run basically any exe as a service. The setup is a little convoluted (requires a registry edit), but should work for most things that can be run as a user applicaiton.
If you can't modify the app there are a bunch of 'run as service' wrappers.
I have used cygrunsrv.exe, I think it works with non-cygwin executables.
If you can't change the code then you cannot directly run the app as a service. However it should not be difficult to Make a Win32 service - it all revolves around calling one api: StartServiceCtrlDispatcher. In response to commands from the service control manager your wrapper service would CreateProcess etc. on the memcached application.
精彩评论