创建服务时如何传入上下文参数

创建服务时如何传入上下文参数

本文介绍了使用 sc.exe 创建服务时如何传入上下文参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用以下方法创建 Windows 服务时:

When creating Windows service using:

sc create ServiceName binPath= "the path"

如何将参数传递给安装程序类的 Context.Parameters 集合?

how can arguments be passed to the Installer class's Context.Parameters collection?

我对 sc.exe 文档的阅读是,此类参数只能在 binPath 的末尾传递,但我还没有找到示例或能够成功做到这一点.

My reading of the sc.exe documentation is that such arguments could only be passed on the end of binPath, but I have not found an example or been able to successfully do this.

推荐答案

sc create <servicename> binpath= "<pathtobinaryexecutable>" [option1] [option2] [optionN]

诀窍是在 create 语句中的 = 后留一个空格,并且对包含特殊字符或空格的任何内容使用".

The trick is to leave a space after the = in your create statement, and also to use " " for anything containing special characters or spaces.

建议为服务指定一个显示名称,并将启动设置设置为自动,以便它自动启动.您可以通过在创建语句中指定 DisplayName= yourdisplaynamestart= auto 来实现.

It is advisable to specify a Display Name for the service as well as setting the start setting to auto so that it starts automatically. You can do this by specifying DisplayName= yourdisplayname and start= auto in your create statement.

这是一个例子:

C:\Documents and Settings\Administrator> sc create asperacentral
binPath= "C:\Program Files\Aspera\Enterprise Server\bin\Debug\asperacentral.exe"
DisplayName= "Aspera Central"
start= auto

如果这有效,您应该看到:

If this worked you should see:

[SC] CreateService SUCCESS

更新 1

http://support.microsoft.com/kb/251192

这篇关于使用 sc.exe 创建服务时如何传入上下文参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 06:38