delphi 操作注册表


function CheckAutoRun: Boolean; 
var
  Reg: TRegistry; //首先定义一个TRegistry类型的变量Reg
begin
  Result:= False;
  Reg:=TRegistry.Create;
  try //创建一个新键
    Reg.RootKey:=HKEY_LOCAL_MACHINE; //将根键设置为HKEY_LOCAL_MACHINE
    Reg.OpenKey('Software\Microsoft\Windows\CurrentVersion\Run',true);//打开一个键
    if Reg.ValueExists('KJKP-PFT') then
    begin
      if Reg.ReadString('KJKP-PFT')=APPPATH+ 'temp\AutoUpgrader.exe' then
        Result:= True;
    end;
    Reg.CloseKey; //关闭键
  finally
    Reg.Free;
  end;

end;

procedure SetAutoRun;
var
  Reg: TRegistry; //首先定义一个TRegistry类型的变量Reg
begin
  Reg:=TRegistry.Create;
  try //创建一个新键
    Reg.RootKey:=HKEY_LOCAL_MACHINE; //将根键设置为HKEY_LOCAL_MACHINE
    Reg.OpenKey('Software\Microsoft\Windows\CurrentVersion\Run',true);//打开一个键
    Reg.WriteString('KJKP-PFT', APPPATH+ 'temp\AutoUpgrader.exe'); //在Reg这个键中写入数据名称和数据数值
    Reg.CloseKey; //关闭键
  finally
    Reg.Free;
  end;
end;

点击打开链接

猜你喜欢

转载自blog.csdn.net/liang08114/article/details/79818999