Inno Setup RegQueryStringValue is not reading values from HKEY_LOCAL_MACHINE

Viewed 115

I created a setup to check the product name and the CurrentMajorVersionNumber of Windows Server 2019 Datacenter in Inno Setup.

But for any reason I can not get any logs in the Inno Setup file.

I checked the registry location for Server 2019 which is Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion.
The ProductName in the registry is REG_SZ.
The CurrentMajorVersionNumber in the registry is REG_DWORD.

function InitializeSetup(): Boolean;
var
  ProductName: string;
  CurrentMajorVersionNumber: string;  
begin
  if RegQueryStringValue(
       HKEY_LOCAL_MACHINE, '\SOFTWARE\Microsoft\Windows NT\CurrentVersion',
       'ProductName', ProductName) then
  begin        
    Log('  > ProductName:' + ProductName)
  end;

  if RegQueryStringValue(
       HKEY_LOCAL_MACHINE, '\SOFTWARE\Microsoft\Windows NT\CurrentVersion',
       'CurrentMajorVersionNumber', CurrentMajorVersionNumber) then
  begin        
    Log('  > CurrentMajorVersionNumber:' + CurrentMajorVersionNumber)
  end;
end;

When the above code is ran there is no log available. Reading other post on this platform regarding this topic could not help me. Is there any fix?

1 Answers

Inno Setup is 32-bit application. It by default gets redirected to HKLM\SOFTWARE\WOW6432Node, when you try to access HKLM\SOFTWARE on 64-bit system.

If you want to access the real HKLM\SOFTWARE on 64-bit system, use HMLM64. You may need to use IsWin64 to choose between HKLM32 and HKLM64, if you need to support both systems.


Second thing is that you cannot use RegQueryStringValue to read REG_DWORD values. You need to use RegQueryDWordValue.

Related