DeleteService function (winsvc.h)

Marks the specified service for deletion from the service control manager database.


BOOL DeleteService(
  [in] SC_HANDLE hService


[in] hService

A handle to the service. This handle is returned by the OpenService or CreateService function, and it must have the DELETE access right. For more information, see Service Security and Access Rights.

Return value

If the function succeeds, the return value is nonzero.

If the function fails, the return value is zero. To get extended error information, call GetLastError.

The following error codes may be set by the service control manager. Others may be set by the registry functions that are called by the service control manager.

Return code Description
The handle does not have the DELETE access right.
The specified handle is invalid.
The specified service has already been marked for deletion.


The DeleteService function marks a service for deletion from the service control manager database. The database entry is not removed until all open handles to the service have been closed by calls to the CloseServiceHandle function, and the service is not running. A running service is stopped by a call to the ControlService function with the SERVICE_CONTROL_STOP control code. If the service cannot be stopped, the database entry is removed when the system is restarted.

The service control manager deletes the service by deleting the service key and its subkeys from the registry.


For an example, see Deleting a Service.


Requirement Value
Minimum supported client Windows XP [desktop apps only]
Minimum supported server Windows Server 2003 [desktop apps only]
Target Platform Windows
Header winsvc.h (include Windows.h)
Library Advapi32.lib
DLL Advapi32.dll

See also





Service Functions

Service Installation, Removal, and Enumeration