WIN32 Service Program (ii): Uninstall service

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.