sc.exe如何设置windows服务的描述?

siv*_*vaL 32 c# windows-services

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

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

它创造了服务.我能够启动这项服务.我能够使用sc.exe命令创建的许多实例

服务

名称| 说明 | 状态| 开始输入| 登录为

说明部分是空白的,我想设置descriptionm,使用sc.exe命令设置服务描述的方法是什么?

Don*_*nal 64

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

sc description TestService1 "This is the description of the service.."
Run Code Online (Sandbox Code Playgroud)

有关更多信息,请参阅此处.

  • 我觉得很奇怪,它不会成为创建命令中的参数。不过这可行,谢谢。我希望微软将来能够加强 Worker Service 模板,以允许通过代码而不是命令行来设置这些内容。 (6认同)
  • 对于那些想以编程方式执行此操作的人:`ChangeServiceConfig2A( service, SERVICE_CONFIG_DESCRIPTION, &desc );` (2认同)

use*_*236 10

不是

sc description TestService1 "TestService1"
Run Code Online (Sandbox Code Playgroud)

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