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.
BOOL DeleteSampleService() { schService = OpenService( schSCManager, // SCManager database TEXT("Sample_Srv"), // name of service DELETE); // only need DELETE access if (schService == NULL) { printf("OpenService failed (%d)/n", GetLastError()); return FALSE; } if (! DeleteService(schService) ) { printf("DeleteService failed (%d)/n", GetLastError()); return FALSE; } else printf("DeleteService succeeded/n"); CloseServiceHandle(schService); return TRUE; }