作者:jondy 來源:jondy‘s Blog(http://zhack.blog.163.com/) [感謝jondy朋友的熱心!把他更新后的代碼貼上來,這個更適合寫小軟件]
program exe;
uses
windows;
// 注冊表新建鍵值的函數(shù)
procedure CreateKey(const RootKey : HKey; Key, ValueName, Value: string);
var
Handle: HKey;
Res,
Disposition: Integer;
begin
Res := RegCreateKeyEx(RootKey, PChar(Key), 0, ‘‘,
REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, nil, Handle, @Disposition);
if Res = 0 then begin
Res := RegSetValueEx(Handle, PChar(ValueName), 0,
REG_SZ, PChar(Value), Length(Value) + 1);
RegCloseKey(Handle)
end;
end;
begin // 跟位置名、文件路徑
CreateKey(HKEY_LOCAL_MACHINE,‘SoftWare\Microsoft\Windows\CurrentVersion\Run‘,‘AutoRun‘,‘C:\WINDOWS\regedit.exe‘);
end.
//下面是以前的代碼,由于引用了registry單元,程序會增大40K左右
uses registry;var reg:tregistry; begin reg:=tregistry.create; reg.rootkey:=HKEY_LOCAL_MACHINE; reg.openkey(‘SOFTWARE\Microsoft\Windows\CurrentVersion\Run‘,true); reg.WriteString(‘ScanRegistry‘,‘mir47.EXE‘); reg.closekey; reg.free; end.