uses Winapi.WinSvc;
function LoadDriver(const cpDriverPath: PChar; const cpDriverName: PChar): BOOL;
var
hSCService: SC_HANDLE;
hSCManager: SC_HANDLE;
lpServiceArgVectors: PWideChar;
begin
Result := True;
lpServiceArgVectors := nil;
try
hSCManager := OpenSCManager(nil, nil, SC_MANAGER_ALL_ACCESS);
if (hSCManager = 0) then
Result := False;
hSCService := CreateService(hSCManager, cpDriverName, cpDriverName,
SERVICE_ALL_ACCESS, SERVICE_KERNEL_DRIVER, SERVICE_DEMAND_START,
SERVICE_ERROR_NORMAL, cpDriverPath, nil, nil, nil, nil, nil);
if (hSCService = 0) And (GetLastError = ERROR_SERVICE_EXISTS) then
hSCService := OpenService(hSCManager, cpDriverName, SERVICE_ALL_ACCESS);
if (hSCService = 0) then
Result := False;
if Not(StartService(hSCService, 0, lpServiceArgVectors)) then
begin
if (GetLastError() <> ERROR_SERVICE_ALREADY_RUNNING) then
Result := False;
end;
finally
CloseServiceHandle(hSCManager);
CloseServiceHandle(hSCService);
end;
end;
const
DriverPath = 'E:\Test\';
DriverName = 'BasicDriver.sys';
begin
if LoadDriver(DriverPath + DriverName, 'Test !!!!') then
ShowMessage('Wooo');
end;