{C} preliminary introduction to the Windows System Service Program

Source: Internet
Author: User

Windows Service programming instructions

 

Service_table_entryStructure array, which records the names of all services contained in the Service Program and the entry point functions of the Service.

Service_table_entry st [] =

{

{Szservicename, (Lpservice_main_function) servicemain },

{Null, null}

};

Startservicectrldispatcher (ST );

/*************************************** ***********************/

// Open the Service Control Manager

SC _handle hscm =: openscmanager (null, null, SC _manager_all_access );

// Open the service

SC _handle hservice =: openservice (hscm,Szservicename, Service_query_config );

: Closeservicehandle (hservice );

: Closeservicehandle (hscm );

// Create a service

SC _handle hservice =: createservice (

Hscm,

Szservicename,

Szservicename,

Service_all_access,

Service_win32_own_process,

Service_demand_start,

Service_error_normal,

Szfilepath, null, null, _ T (""), null, null );

: Closeservicehandle (hservice );

// Delete the service

SC _handle hservice =: openservice (hscm, szservicename, service_stop | delete );

Service_status status;

// Stop the service

: Controlservice (hservice, service_control_stop, & status );

// Delete the service

Bool bdelete =: deleteservice (hservice );

: Closeservicehandle (hservice );

: Closeservicehandle (hscm );

// Register Service Control

Hservicestatus = registerservicectrlhandler (szservicename, servicestrl );

Setservicestatus (hservicestatus, & status );

///////

Void winapi servicestrl (DWORD dwopcode)

{

Switch (dwopcode ){}

}

 

 

 

 

 

/*************************************** ***********************/

Createservice (

SC _handle hscmanager, // the handle of the registration database maintained by the Service Control Manager, which is returned by the system function openscmanager.

Lpwstr lpservicename, // service name ending with null, used to create a keyword in the registration database

Lpcwstr lpdisplayname, // service name ending with null, used to identify the service on the user interface

DWORD dwdesiredaccess, // specify the service return type

DWORD dwservicetype, // specify the service type

DWORD dwstarttype, // specify when to start the service

DWORD dwerrorcontrol, // specify the severity of Service Startup failure

Lpcwstr lpbinarypathname, // specify the path of the binary file of the Service Program (with parameters)

Lpcwstr lploadordergroup, // specify the name of the Service Group loaded in sequence

Lpdword lpdwtagid, // ignore, null

Lpcwstr lpdependencies, // specify the service or service group that must be started before starting the service

Lpwstr lpservicestartname, // string ending with null, specifying the service account. If it is null, the LocalSystem account is used.

Lpcwstr lppassword // string ending with null, specifying the corresponding password. Null indicates no password. However, if LocalSystem is used, enter null.

);

 

 

 

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.