Some of the actions that Windows services implements with C + + code-1: Modifying service startup types

Source: Internet
Author: User

VOID Dosvcstarttype () {Sc_handle schscmanager; Sc_handle Schservice; Get a handle to the SCM database. Schscmanager = OpenSCManager (null,//local computer NULL,//servicesactive database sc_manager_all_access); Full access rights if (NULL = = Schscmanager) {printf ("OpenSCManager failed (%d)/n", GetLastError ()); A handle to the service. Schservice = OpenService (Schscmanager,//SCM database Szsvcname,//Name of service service_change_config); Need change config access if (Schservice = = NULL) {printf ("OpenService failed (%d)/n", GetLastError ()); Closeservicehandle (Schscmanager); Return }//Change the service start type. Sc_lock Scllock; Scllock = Lockservicedatabase (Schservice); if (! Changeserviceconfig (Schservice,//Handle of service Service_no_change,//service Type:no Change//service_change_confi G, Service_demand_start,//SERVICE START type Service_no_change,//Error Control:no change NULL,//binary Path:no Cha Nge NULL,//load order group: No change null,//tag id:no change null,//DEPENDENCIES:NO change NULL,//account Name:no change L "ABC",//Passwo Rd:no change NULL)//display name:no change {//service_change_config printf ("Changeserviceconfig failed (%d)/n", get LastError ()); else printf ("Service enabled successfully./n"); Change the startup type to disable if (! Changeserviceconfig (Schservice,//Handle of service Service_no_change,//service Type:no change service_disabled,//se Rvice_demand_start,//service START type Service_no_change,//Error Control:no change NULL,//binary Path:no change N ull,//load order Group:no change null,//tag id:no change null,//DEPENDENCIES:NO change NULL,//account Name:no Change null,//PASSWORD:NO change null)//display name:no change {//service_change_config printf ("2:changeserviceco Nfig failed (%d)/n ", GetLastError ()); else printf ("2:service enabled successfully./n"); Unlockservicedatabase (Scllock); Closeservicehandle (Schservice); Closeservicehandle (Schscmanager); }

This is the startup type code for the Modify Windows service implemented by C + +. The friend of hobby supports a bit.

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.