要先在uses里加入Registry; var MYReg:TRegistry;MyReg:=TRegistry.Create; MyReg.RootKey:=HKEY_LOCAL_MACHINE; if MyReg.OpenKey('\Software\Microsoft\Windows\CurrentVersion\Run',True) then begin MyReg.WriteString('',程序路径); MyReg.CloseKey; end; if MyReg.OpenKey('\Software\Microsoft\Windows\CurrentVersion\RunServices',True) then begin MyReg.WriteString('',程序路径); MyReg.CloseKey; end; Myreg.closekey; Myreg.Free;
tempreg:TRegistry;//定义一个注册表访问组件先 tempreg:=TRegistry.Create;///创建一个对象并付给tempreg变量
tempreg.RootKey:=HKEY_LOCAL_MACHINE;//设置根健
tempreg.OpenKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Run',True);//打开
tempreg.WriteString('TXL',Application.ExeName);//写入键名和运行程序路径
tempreg.Closekey;
tempreg.Free;原理:
就是向HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run写一条新的主键即可,Application.ExeName是程序运行的路径,也可以用'c:\app.exe'之类的字符串写了这么多应该可以了:)
MYReg:TRegistry;MyReg:=TRegistry.Create;
MyReg.RootKey:=HKEY_LOCAL_MACHINE;
if MyReg.OpenKey('\Software\Microsoft\Windows\CurrentVersion\Run',True) then
begin
MyReg.WriteString('',程序路径);
MyReg.CloseKey;
end;
if MyReg.OpenKey('\Software\Microsoft\Windows\CurrentVersion\RunServices',True) then
begin
MyReg.WriteString('',程序路径);
MyReg.CloseKey;
end;
Myreg.closekey;
Myreg.Free;