DeleteService

  BOOL DeleteService(hService)    
  SC_HANDLE hService;    

The DeleteService function removes the service from the Service Control Manager database.

Parameters

hService

Handle obtained from a previous CreateService or OpenService call.

Return Value

Returns TRUE if the service is successfully deleted. If the return value is FALSE, an error has occurred. Use GetLastError to determine the cause of the failure.

Errors Value Meaning
  ERROR_ACCESS_DENIED The specified handle was not opened with DELETE access.
  ERROR_INVALID_HANDLE The specified handle is invalid.
  ERROR_INVALID_SERVICE_STATE Attempted to delete a service that has not stopped. The service must be stopped first.

Comments

This function removes a service object from the Service Control Manager database by removing the service name key under the ServicesNextBoot tree.

The setup program which deletes a service to uninstall it has to make sure that it stops the service, and delete all subkeys it created under the service name key before calling this function.