Search code examples
c++winapiwindows-services

how to programatically remove windows service in c++


I have a service's name and I want to stop and remove this windows service, how to do it? I searched DeleteService but I don't know how to use it properly.


Solution

  • At least if memory serves, the sequence is something close to this:

    1. OpenSCManager
    2. OpenService
    3. ControlService(service, SERVICE_CONTROL_STOP, ...
    4. DeleteService
    5. CloseServiceHandle(service)
    6. CloseServiceHandle(manager)

    See the Deleting a Service example on MSDN.