• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

在安装而不是每次启动时一劳永逸地参数传递把 Windows 服务

用户头像
it1352
帮助1

问题说明

我们有一个可以接受命令行参数的 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.

正确答案

#1
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
系列文章
更多 icon
同类精品
更多 icon
继续加载