On the Internet, you can see a source code that can load the driver... ...
Code
**************************************** *******************************}
{Module name: mydriver}
{Module function: load/uninstall driver}
{Version No.: v1.0.0}
{Date}
{*************************************** ********************************}
Unit mydriver;
Interface
Uses
Windows, sysutils, tlhelp32, winsvc;
{Function: load the driver
Parameter: szthedrivername: Path of the driver.
Szsvrname: Driver name .}
Function installdriver (szthedrivername, szsvrname: string): Boolean;
{Function: uninstall the driver.
Parameter: szsvrname: Driver name .}
Function uninstalldriver (szsvrname: string): Boolean;
Implementation
Function installdriver (szthedrivername, szsvrname: string): Boolean;
VaR
Hservicemgr, hservicetwdm: SC _handle;
Szdir: array [0 .. 1023] of char;
Lpszthedrivername, P: pchar;
Begin
Zeromemory (@ szdir, 1024 );
Strcopy (szdir, pchar (szthedrivername ));
Lpszthedrivername: = @ szdir;
{Open service control manager}
Hservicemgr: = openscmanager (nil, nil, SC _manager_all_access );
If hservicemgr = 0 then
Begin
{Openscmanager () faild .}
Result: = false;
Exit;
End;
Hservicetwdm: = createservice (hservicemgr,
Pchar (szsvrname), {name of the System \ CurrentControlSet \ Services driver in the Registry}
Pchar (szsvrname), {displayname value of the registry driver}
Service_all_access, {permission to load the driver}
Service_kernel_driver, {indicates that the loaded service is a driver}
Service_demand_start, {start value of the registry driver}
Service_error_ignore, {errorcontrol value of the registry driver}
Lpszthedrivername, {registry driver's ImagePath value}
Nil, nil, nil );
If hservicetwdm = 0 then
Begin
If getlasterror () = error_service_exists then
Begin
{Service exists}
Hservicetwdm: = openservice (hservicemgr, pchar (szsvrname), service_all_access );
If hservicetwdm = 0 then
Begin
Closeservicehandle (hservicemgr );
Result: = false;
Exit;
End;
End
Else
Begin
Closeservicehandle (hservicemgr );
Result: = false;
Exit;
End;
End;
{Start the drivers}
If hservicetwdm <> 0 then
Begin
If startservice (hservicetwdm, 0, P) = false then
Begin
If error_service_already_running = getlasterror () then
Begin
{No real problem}
End
Else
Begin
Closeservicehandle (hservicemgr );
Closeservicehandle (hservicetwdm );
Result: = false;
Exit;
End;
End;
Closeservicehandle (hservicemgr );
Closeservicehandle (hservicetwdm );
End;
Result: = true;
End;
Function uninstalldriver (szsvrname: string): Boolean;
VaR
Hservicemgr, hservicetwdm: SC _handle;
Svrsta: service_status;
Begin
Hservicemgr: = openscmanager (nil, nil, SC _manager_all_access );
If hservicemgr = 0 then
Begin
{Openscmanager () faild .}
Result: = false;
Exit;
End;
Hservicetwdm: = openservice (hservicemgr, pchar (szsvrname), service_all_access );
If hservicetwdm = 0 then
Begin
{Openservice () faild .}
Closeservicehandle (hservicemgr );
Result: = false;
Exit;
End;
{Stop the driver. If the stop fails, the driver can be dynamically loaded only after it is restarted .}
If controlservice (hservicetwdm, service_control_stop, svrsta) = false then
Begin
{Controlservice () faild .}
Closeservicehandle (hservicetwdm );
Closeservicehandle (hservicemgr );
Result: = false;
Exit;
End;
{Dynamically uninstall the driver .}
If deleteservice (hservicetwdm) = false then
Begin
{Deletesrevice () faild .}
Closeservicehandle (hservicetwdm );
Closeservicehandle (hservicemgr );
Result: = false;
Exit;
End;
Closeservicehandle (hservicetwdm );
Closeservicehandle (hservicemgr );
Result: = true;
End;
End.