在C++中设置Windows服务描述

Set Windows Service Description in C++

本文关键字:服务 描述 Windows 设置 C++      更新时间:2023-10-16

我正在使用CreateService安装Windows服务可执行文件,但我似乎找不到如何设置服务的描述。

有人知道怎么做吗?

谢谢。

调用ChangeServiceConfig2,传递SERVICE_CONFIG_DESCRIPTION作为dwInfoLevel参数。您还需要一个服务句柄,但CreateService会为您提供其中一个句柄。

SERVICE_DESCRIPTION description = { L"The service description" };
ChangeServiceConfig2(hService, SERVICE_CONFIG_DESCRIPTION, &description);

请查看此MSDN页面以获取示例。使用ChangeServiceConfig2方法。

SERVICE_DESCRIPTION sd;
SC_HANDLE schService;
SC_HANDLE schSCManager;
// Not shown: Get a handle to the SCM database. 
// Not shown: Get a handle to the service.
sd.lpDescription = TEXT("Description");
ChangeServiceConfig2( schService,                 // handle to service
                      SERVICE_CONFIG_DESCRIPTION, // change: description
                      &sd) )                      // new description