作者:jondy 来源:jondy‘s Blog(http://zhack.blog.163.com/)
[感谢jondy朋友的热心!把他更新后的代码贴上来,这个更适合写小软件]
program exe;
uses
windows;
// 注册表新建键值的函数
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.