16

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.

Nick
  • 25,026
  • 7
  • 51
  • 83

2 Answers2

20

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);
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • Perfect. Spent ages trying to find this! – Nick Mar 13 '12 at 13:09
  • 2
    Worth to mention that the service has to be created with the SERVICE_CHANGE_CONFIG right, otherwise you'll get an "access denied" and the description will not be set. – hfrmobile Jul 28 '15 at 11:53
6

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
Konrad
  • 39,751
  • 32
  • 78
  • 114