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.
);