To load the driver properly, follow these steps:
1. Call openscmanager to open the SCM manager. If null is returned, an error is returned; otherwise, the next step is continued;
2. Call createservice to create a service. If the returned value obtained by getlasterror is error_io_pending, it indicates that the service has been created and openservice is used to open the service.
3. Call startservice to enable the Service.
Openscmanager --> createservice --> openservice --> startservice --> closeservicehandle
SC _handle openscmanager (
Lpctstr Lpmachinename,
// Point to the computer name. null indicates pointing to the local machine.
Lpctstr Lpdatabasename,
// SCM database name. The default value is null.
DWORD Dwdesiredaccess// The permission is generally set to SC _manager_all_access, indicating that all permissions are granted.
);
// The SCM handle to close
Boolcloseservicehandle (SC _handle Hscobject)
// Open the Service Control Manager
Openscmanager (null, null, SC _manager_all_access );
// Create the service corresponding to the driver
Createservice (hservicemgr, // SCM manager handle
Lpszdrivername, // name of the driver in the Registry
Lpszdrivername, // displayname value of the registry driver
Service_all_access, // access permission for loading the driver
Service_kernel_driver, // indicates that the loaded service is a driver.
Service_demand_start, // The start value of the registry driver
Service_error_ignore, // The errorcontrol value of the registry driver
Szdriverimagepath, // The ImagePath value of the registry driver
Null, // user group to enable the Service
Null, // output validation tag
Null, // The Name Of The dependent service
Null, // User Account Name
Null); // User Password
// The driver has been loaded. You only need to open
Openservice (hservicemgr, lpszdrivername, service_all_access );
// Enable this service
Startservice (hserviceddk, null, null );