Пишем библиотеку:
library autorun;
uses
Windows,
Registry;
{$R *.res}
procedure RunOnWinStart(Flag:boolean; NameParam, Path:String);
var Reg:TRegistry;
begin
if Flag then
begin
Reg := TRegistry.Create;
Reg.RootKey := HKEY_CURRENT_USER;
Reg.OpenKey('\SOFTWARE\Microsoft\Windows\CurrentVersion\Run', false);
Reg.WriteString(NameParam, Path);
Reg.Free;
end
else
begin
Reg := TRegistry.Create;
Reg.RootKey := HKEY_CURRENT_USER;
Reg.OpenKey('\SOFTWARE\Microsoft\Windows\CurrentVersion\Run',false);
Reg.DeleteValue(NameParam);
Reg.Free;
end;
end;
exports
RunOnWinStart;
begin
end.
library autorun;
uses
Windows,
Registry;
{$R *.res}
procedure RunOnWinStart(Flag:boolean; NameParam, Path:String);
var Reg:TRegistry;
begin
if Flag then
begin
Reg := TRegistry.Create;
Reg.RootKey := HKEY_CURRENT_USER;
Reg.OpenKey('\SOFTWARE\Microsoft\Windows\CurrentVersion\Run', false);
Reg.WriteString(NameParam, Path);
Reg.Free;
end
else
begin
Reg := TRegistry.Create;
Reg.RootKey := HKEY_CURRENT_USER;
Reg.OpenKey('\SOFTWARE\Microsoft\Windows\CurrentVersion\Run',false);
Reg.DeleteValue(NameParam);
Reg.Free;
end;
end;
exports
RunOnWinStart;
begin
end.
Далее в программе делаем ее динамическое выполнение:
procedure SetRunOnStart(const Value: boolean);
var
LibHandle:Integer;
Fc_AutoRun: procedure(Flag:boolean; NameParam, Path:String);
begin
FRunOnStart := Value;
LibHandle := LoadLibrary('autorun.dll');
if LibHandle >=32 then
begin
@Fc_AutoRun := GetProcAddress(LibHandle, 'RunOnWinStart');
Fc_autoRun(Value, Application.title, paramstr(0));
end;
FreeLibrary(LibHandle);
end;
Комментариев нет:
Отправить комментарий