将 Windows 应用程序作为服务运行?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2869392/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Run Windows application as a service?
提问by sh-beta
What is the cleanest, most reliable way to run a Windows application as a service without touching its code?
在不触及其代码的情况下将 Windows 应用程序作为服务运行的最干净、最可靠的方法是什么?
Use case: NorthScale's 64-bit Windows version of memcachedruns 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.
用例:NorthScale 的 64 位 Windows 版本的 memcached作为通用应用程序运行。我想将它粘贴到 Windows 2003 或 2008 服务中,以便我可以通过标准界面启动/停止/重新启动/等。
回答by ig0774
The Windows Resource Kithas 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.
在Windows资源工具包有任何可执行文件,srvany.exe
可以使用的,如所描述这里,基本上运行任何exe文件的服务。设置有点复杂(需要编辑注册表),但应该适用于大多数可以作为用户应用程序运行的事情。
回答by Martin Beckett
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.
如果您无法修改应用程序,则有一堆“作为服务运行”的包装器。
我使用过 cygrunsrv.exe,我认为它适用于非 cygwin 可执行文件。
回答by Chris Becke
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.
如果您无法更改代码,则无法直接将应用程序作为服务运行。然而,制作 Win32 服务应该不难——这一切都围绕着调用一个 api:StartServiceCtrlDispatcher。为了响应来自服务控制管理器的命令,您的包装器服务将在 memcached 应用程序上创建进程等。