|
- //OpenSCManager - > CreateService - > StartService 大概流程是这样...
- function LoadDriver(lpService, lpFileName: string): Boolean;
- const
- METHOD_BUFFERED = $00000000;
- FILE_SPECIAL_ACCESS = $00000000;
- FILE_DEVICE_FILE_SYSTEM = $00000009;
- FSCTL_SET_SPARSE = FILE_DEVICE_FILE_SYSTEM shl 16 or FILE_SPECIAL_ACCESS shl 14 or 49 shl 2 or METHOD_BUFFERED;
- var
- pStart: Pchar;
- hFile: THandle;
- hSC, hSvc: THandle;
- BytesReturned: Cardinal;
- hStatus: SERVICE_STATUS;
- begin
- Result := False;
- if not FileExists(Pchar(lpFileName)) then Exit;
- hSC := OpenSCManager(nil, nil, SC_MANAGER_ALL_ACCESS);
- try
- if hSC <> 0 then
- begin
- hSvc := CreateService(hSC, PChar(lpService), PChar(lpService), SERVICE_START or SERVICE_STOP, SERVICE_KERNEL_DRIVER,
- SERVICE_DEMAND_START, SERVICE_ERROR_IGNORE, PChar(lpFileName), nil, nil, nil, nil, nil);
- if ERROR_SERVICE_EXISTS = GetLastError() then
- begin
- hSvc := OpenService(hSC, PChar(lpService), SERVICE_START);
- end;
- StartService(hSvc, 0, pStart);
- {ControlService(hSvc, SERVICE_CONTROL_STOP, hStatus);
- DeleteService(hSvc); }//这里是停止和删除服务的,哈哈
- end;
- finally
- CloseServiceHandle(hSC);
- end;
- end;
复制代码 |
|