开机启动注册路径:
64位操作系统: HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Run
32位操作系统: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run
WOW64 注册表反射器可能会在反射过程中修改注册表项的内容和项值,目的是为了调整路径名等。因此,32 位的内容与 64 位的内容可能会有所不同。
function TfmMain.SetReg(aReg: boolean): Boolean;
var
regf: Tregistry;
key: string;
sPath, sValue: string;
bValue: Boolean;
begin
Result := False;
regf := TRegistry.Create;
try
try
key := 'SOFTWARE\Microsoft\Windows\CurrentVersion\Run';
regf.RootKey := HKEY_LOCAL_MACHINE;
if regf.KeyExists(key) then
begin
if regf.OpenKey(key, FALSE) then
begin
sPath := Format('%s %s %s', [Application.ExeName, '-zd', '30000']); //延时启动时间
sValue := Trim(regf.ReadString(sKeyName));
bValue := sValue = sPath;
if aReg then
begin
if not bValue then
begin
regf.WriteString(sKeyName, sPath);
end;
end
else
begin
if bValue then
regf.DeleteValue(sKeyName);
end;
Result := True;
end;
end;
SystemLog(' 操作注册表 - [Success]');
except
on E: Exception do
begin
SystemLog(Format('操作注册表 - [Failure:%s]', [E.Message]));
end;
end;
finally
regf.Free;
end;
end;
参数设置True 写入、更新注册表项
参数设置False, 删除注册表项
代码里实际写的32位系统的启注册路径,但是操作系统是64位的, 默认使用64位注册表项。路径按64位来看: