Delete Windows Services

Source: Internet
Author: User

Transferred from: I _like_cpp's blog

Delete Windows Services
 
This question is boring for programmers, but it is quite useful in some cases. I deleted and uninstalled a software, but all the results were deleted. The result service was still there. It was very unsightly. I couldn't find the Registry again, so I had to write a small one myself.ProgramTo delete a service.

First, complete the interface as follows:

To use Windows service management function groups, you must first open the Service Manager, which includes winsvc. h In the header file.
Add the SC _handle sh; definition to the dialog box class.
Add the following to the oninitdialog member function: Code To initialize service management.
SH = openscmanager (0, services_active_database, SC _manager_all_access); If (! SH) {MessageBox ("faile to open scmanager"); Return false ;}
Add to onclose member function
Closeservicehandle (SH );

Then process two button events
Void cdelsdlg: listservices () {// todo: add your control notification handler code here DWORD Eh = 0, D1, nret, I; bool ret; SCV. resetcontent (); ret = enumservicesstatus (Sh, service_win32 | service_driver, service_inactive, ESS, sizeof (ESS), & D1, & nret, & EH); If (! RET) {char temp [32]; sprintf (temp, "% d", getlasterror (); MessageBox (temp); MessageBox ("failed to Enum services "); return;} for (I = 0; I <nret; I ++) {SCV. addstring (ESS [I]. lpdisplayname );}}

Void cdelsdlg: delservice () {// todo: add your control notification handler code here int I, RET; char temp [256]; I = SCV. getcursel (); sprintf (temp, "Do you realy want to remove the service \ r \ n" "% d: \ t % s \ r \ n % s", I, ESS [I]. lpservicename, ESS [I]. lpdisplayname); ret = MessageBox (temp, "alert! ", Mb_yesno | mb_iconwarning | mb_defbutton2); If (ret = idyes) {SC _handle Ds; DS = openservice (Sh, ESS [I]. lpservicename, SC _manager_all_access); If (! DS) {MessageBox ("failed to open service"); return;} If (deleteservice (DS) {MessageBox ("success to remove the service ");} else {sprintf (temp, "failed to remove the service \ r \ nerror code: \ t % d", getlasterror (); MessageBox (temp );} closeservicehandle (DS );}}
The former enumerates non-active services and adds them to the list box. The latter directly deletes the corresponding services.

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.