例:列出注册表"HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run"中的所有键值到界面上或文本中;并把自己做的这个程序设置为开机启动。(写到前面那个注册表路径上就生效了)
unit Unit1;interfaceusesWindows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,Dialogs, registry, StdCtrls;typeTForm1 = class(TForm)Button1: TButton;Show: TMemo;procedure Button1Click(Sender: TObject);private{ Private declarations }public{ Public declarations }end;varForm1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
varm_Reg: Tregistry;m_KeyList: TStrings;i, j: Integer;AppPath:string;
beginShow.Lines.Clear;m_Reg := TRegistry.Create;m_KeyList := TStringList.Create;m_Reg.RootKey := HKEY_CURRENT_USER;//false:不存在的话 也不创建if m_Reg.OpenKey('\SOFTWARE\Microsoft\Windows\CurrentVersion\Run', false) thenbegin//获取所有值存入list中m_Reg.GetValueNames(m_KeyList);for i := 0 to m_KeyList.Count - 1 dobeginShow.Lines.Add(m_KeyList[i] + ': ' + m_Reg.ReadString(m_KeyList[i]));end;//获取当前可执行文件的路径APPpath:=ExtractFilePath(Application.ExeName)+Application.Title+'.exe';m_Reg.WriteString('Day01Pro',AppPath);endelsebeginShowMessage('open Run err!');end;m_Reg.Free;m_KeyList.Free;
end;end.