Delphi 7 x64 registry

2

I tested the following on a Windows 8 machine: I inserted a Windows registry key for startup. On Windows XP and Windows 7 that were 32-bit worked but on Windows 8 it's 64-bit did not work. Can someone give me a hand? How to insert a registry key in Windows 8 - 64 bit? Below is the code I've tried.

var
Reg: TRegistry;
S: string;

begin
Reg := TRegistry.Create;
S:= variavelcontendocaminhoearqv;
Reg.rootkey:=HKEY_CURRENT_USER;
Reg.Openkey('software\microsoft\windows\currentversion\run\',true);
Reg.WriteString('programtest',S);
Reg.closekey;
Reg.Free;
end;
    
asked by anonymous 19.04.2015 / 09:02

1 answer

4

You may need to pass the value KEY_WOW64_64KEY in the constructor.

// Uses Registry;
procedure inicializarPrograma(App, Caminho: string);
const 
  KEY_WOW64_64KEY = $0100; 
var
  Reg: TRegistry;
begin
  Reg := TRegistry.Create(KEY_WRITE OR KEY_WOW64_64KEY); //
  try
    Reg.RootKey := HKEY_CURRENT_USER;
    if Reg.OpenKey('Software\Microsoft\Windows\CurrentVersion\Run', True) then
     Reg.WriteString(App, Caminho);
    Reg.CloseKey;
  finally
    Reg.Free;
  end;
end;

Example usage:

inicializarPrograma(Caption, ParamStr(0));
    
19.04.2015 / 19:05