在安装而不是每次启动时一劳永逸地参数传递把 Windows 服务
问题说明
我们有一个可以接受命令行参数的 Windows 服务应用程序,例如:
We have a Windows Service application that can accept command line parameters like:
MyService -option
到目前为止,当我们想用参数启动服务时,我们要么从服务属性对话框(在启动参数框中)手动执行,要么使用命令
So far, when we want to start the service with a parameter, we either do it manually from the Service Properties dialog (in the Start parameters box) or with the command
sc start MyService -option
我们想要的是一种使用此参数永久"安装服务的方法,这样用户只需启动/停止它,而不必每次都设置参数时间.
What we would like is a way to install the service "permanently" with this parameter, so that the users would just have to start/stop it without having to set the parameter each time.
顺便说一句,在 ImagePath 注册表项中添加参数不起作用,这样安装也不起作用:
BTW, adding the parameter in the ImagePath registry entry doesn't work, neither does installing like this:
MyService -option /install
更新:感谢您到目前为止的回答,它们帮助我完善了问题.
我想要实现的是在服务级别本身(与属性一样)设置参数,以防同一个可执行文件中有超过 1 个服务.binpath 配置选项只是更新注册表中的 ImagePath 条目.这不能是特定于服务的.
Updated: Thank you for the answers so far which help me refine the question.
What I'd like to achieve is to set the parameter at the Service level itself (like with the properties) in case there are more than 1 service in the same executable. The binpath config option is merely updating the ImagePath entry in the registry. That cannot be service specific.
正确答案
sc config MyService binPath= MyService.exe -option
更新
各个服务参数存储在注册表中的注册表项 HKLMSYSTEMCurrentControlSetServicesParameters
处.我不确定参数是如何传递给服务的.我相信当 SCM 调用 StartService
它将它们传递给 ServiceMain
回调.
The individual service parameters are stored in the the registry at the key HKLMSYSTEMCurrentControlSetServices<serviceName>Parameters
. I'm not sure though how the parameters are passed to the service. I believe SCM reads these values then when it calls StartService
it passes them to the ServiceMain
callback.
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /reply/detail/tanhcfickj
-
YouTube API 不能在 iOS (iPhone/iPad) 工作,但在桌面浏览器工作正常?
it1352 07-30 -
iPhone,一张图像叠加到另一张图像上以创建要保存的新图像?(水印)
it1352 07-17 -
保持在后台运行的 iPhone 应用程序完全可操作
it1352 07-25 -
使用 iPhone 进行移动设备管理
it1352 07-23 -
在android同时打开手电筒和前置摄像头
it1352 09-28 -
扫描 NFC 标签时是否可以启动应用程序?
it1352 08-02 -
检查邮件是否发送成功
it1352 07-25 -
Android微调工具-删除当前选择
it1352 06-20 -
希伯来语的空格句子标记化错误
it1352 06-22 -
Android App 和三星 Galaxy S4 不兼容
it1352 07-20