【问题标题】:sc.exe how to set up the description for the windows Service?sc.exe如何设置windows服务的描述?
【发布时间】:2015-06-24 12:16:18
【问题描述】:

我正在使用 sc.exe 命令安装 C# windows 服务。

C:Windows\System32> sc.exe Create "TestService1" binPath= "C:\Program Files (x86)\Test\TestService1" DisplayName= "TestWindowsService1"

它创建了服务。我能够启动该服务。我可以使用 sc.exe 命令创建许多实例

查看服务

姓名 | 说明 |状态 |开始类型 |以身份登录

描述部分是空白的,我想设置描述,有什么方法可以使用 sc.exe 命令为服务设置描述?

【问题讨论】:

  • 创建服务后,调用“sc description [service name] [description]”设置描述。

标签: c# windows-services


【解决方案1】:

您需要再次调用 sc 来设置描述。例如:

sc description TestService1 "This is the description of the service.."

有关详细信息,请参阅here

【讨论】:

  • 我觉得奇怪的是它不会是 create 命令中的参数。不过,这行得通,谢谢。我希望将来 MS 能够加强 Worker Service 模板,以允许通过代码而不是命令行来设置这些东西。
  • 对于那些想以编程方式执行此操作的人:ChangeServiceConfig2A( service, SERVICE_CONFIG_DESCRIPTION, &desc );
【解决方案2】:

不是

sc description TestService1 "TestService1"

根据文档:https://technet.microsoft.com/en-us/library/cc742069.aspx?

【讨论】:

    【解决方案3】:

    对于那些在尝试使用“sc description”命令时遇到“找不到接受参数的位置参数”(PositionalParameterNotFound)错误的用户,请将 sc 替换为 sc.exe。显然它解决了问题,尽管“sc create”命令按预期工作,没有 .exe

    【讨论】:

      猜你喜欢
      • 2012-03-29
      • 2023-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多