Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Windows Service Description in C++

Tags:

c++

unmanaged

I am using CreateService to installs a Windows Service executable however I can't seem to find out how to set the description for the service.

Does anyone know how to do this?

Thanks.

like image 790
Nick Avatar asked Mar 13 '12 12:03

Nick


People also ask

How do I change the description of a Windows service?

Service descriptions are kept in the registry under LocalMachine\System\CurrentControlSet\services and then open the key for your service name, one of the keys is Description which holds the description text. Change that and restart the computer.

What is Windows Services in C#?

A Windows service is a long-running application that can be started automatically when your system is started. You can pause your service and resume or even restart it if need be. Once you have created a Windows service, you can install it in your system using the InstallUtil.exe command line utility.


2 Answers

Call ChangeServiceConfig2 passing SERVICE_CONFIG_DESCRIPTION as the dwInfoLevel parameter. You will also need a handle to the service, but CreateService gives you one of those.

SERVICE_DESCRIPTION description = { L"The service description" };
ChangeServiceConfig2(hService, SERVICE_CONFIG_DESCRIPTION, &description);
like image 117
David Heffernan Avatar answered Sep 20 '22 05:09

David Heffernan


Have a look at this MSDN page for an example. You use the ChangeServiceConfig2 method.

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
like image 34
Konrad Avatar answered Sep 20 '22 05:09

Konrad