📄 unit1.pas
字号:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, WinSVC;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var hscManager: thandle;
hservicE: thandle;
var sav: pchar;
apppath: pchar;
win32kaddress,win32size:dword;
kernel32dll: thandle;
driverloc:string;
hdevice: thandle;
// servicestatus: _service_status;
begin
kernel32dll:=loadlibrary('kernel32.dll');
apppath:=nil;
hSCManager := OpenSCManager(nil, nil, GENERIC_READ or GENERIC_WRITE);
try
getmem(apppath,250);
GetModuleFileName(0,apppath,250);
driverloc:=extractfilepath(apppath)+edit1.text;
finally
freemem(apppath);
end;
if hscmanager<>0 then
begin
hService := OpenService(hSCManager, pchar(edit2.text), SERVICE_ALL_ACCESS);
if hService=0 then
begin
hService:=CreateService(
hSCManager, // SCManager database
pchar(edit2.text), // name of service
pchar(edit2.text), // name to display
SERVICE_ALL_ACCESS, // desired access
SERVICE_KERNEL_DRIVER,// service type
SERVICE_DEMAND_START, // start type
SERVICE_ERROR_NORMAL, // error control type
pchar(driverloc), // service's binary
nil, // no load ordering group
nil, // no tag identifier
nil, // no dependencies
nil, // LocalSystem account
nil // no password
);
end
else
begin
//make sure the service points to the right file
ChangeServiceConfig(hservice,
SERVICE_KERNEL_DRIVER,
SERVICE_DEMAND_START,
SERVICE_ERROR_NORMAL,
pchar(driverloc),
nil,
nil,
nil,
nil,
nil,
pchar(edit2.text));
end;
if hservice<>0 then
begin
sav:=nil;
startservice(hservice,0,sav);
closeservicehandle(hservice);
end else
begin
messagebox(0,'The service couldn''t get opened and also couldn''t get created.'+' Check if you have the needed rights to create a service, or call your system admin (Who''ll probably beat you up for even trying this). Untill this is fixed you won''t be able to make use of the enhancements the driver gives you','DBK32 Error',MB_ICONERROR or mb_ok);
hDevice:=INVALID_HANDLE_VALUE;
exit;
end;
end;
application.Terminate;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -