The process of uninstalling the service is this, open the SCM with OpenSCManager, use OpenService to open the service to be uninstalled, and through QueryServiceStatus query the status of the service is stopped, if no, Then stop the service ControlService and finally delete the service with DeleteService.
1#include <windows.h>2#include <winsvc.h>3#include <stdio.h>4 5 voiduninstallservices ();6 voidMain ()7 {8 uninstallservices ();9 }Ten One A voiduninstallservices () - { - Charname[ -]; the sc_handle SCM; - Sc_handle Service; - service_status STATUS; - +printf"Service Name:"); -scanf"%s",&name); + A if(SCM = OpenSCManager (null,null,sc_manager_create_service)) = =NULL) atprintf"error!\n"); - -Service = OpenService (scm,name,service_all_access |DELETE); -BOOL issuccess = QueryServiceStatus (service,&status); - if(Status.dwcurrentstate! =service_stopped) - { inissuccess = ControlService (service,service_control_stop,&status); -Sleep ( -); to } +Issuccess =DeleteService (service); - if(!issuccess) theprintf"Uninstall falid!\n"); * Else $printf"Uninstall success!\n");Panax Notoginseng - closeservicehandle (service); the Closeservicehandle (SCM); +}
By running this program and entering the service name, we can delete the service program that was established.
WIN32 Service Program (ii): Uninstall service