Deleting a Service

In the following example, a service configuration program uses the OpenService function to get a handle with DELETE access to an installed service object. The program then uses the service object handle in the DeleteService function to remove the service from the SCM database.

VOID DeleteSampleService()

{

schService = OpenService(

schSCManager, // SCManager database

TEXT("Sample_Srv"), // name of service

DELETE); // only need DELETE access

if (schService == NULL)

MyErrorExit("OpenService");

if (! DeleteService(schService) )

MyErrorExit("DeleteService");

else

printf("DeleteService SUCCESS\n");

CloseServiceHandle(schService);

}