Brug af RegQueryValueEx funktionen
Jeg skal hente nogle strings fra registry via RegQueryValueEx. Hvordan går jeg det?Jeg har prøvet med:
function GetProgramFilesPath(): string;
// Return the program files path as define in the registry.
// If the function is unable to find the path, it guess on c:\program files and return this.
var
handle: hkey;
Oreturn: integer;
Path: string;
lg: PDWORD;
DataType: integer;
begin
//Result := 'c:\program files';
Path := '';
lg := nil;
DataType := REG_SZ;
Oreturn := RegOpenKeyEx(HKEY_LOCAL_MACHINE, 'Software\Microsoft\Windows\CurrentVersion\', 0, KEY_READ, handle);
if(Oreturn = ERROR_SUCCESS) then begin
OReturn := RegQueryValueEx(handle, 'ProgramFilesDir', nil, @DataType, @Path, @lg);
if(Oreturn = ERROR_SUCCESS) then begin
SetLength(Path, Integer(lg)-1);
Result := Path;
end;
RegCloseKey(handle);
end;
end;
RegQueryValueEx(handle, 'ProgramFilesDir', nil, @DataType, @Path, @lg); retunere værdien 234
