21

I use this code to know if a key exists or not:

if RegKeyExists(HKEY_LOCAL_MACHINE, 'Software\Autodesk') then
begin
  MsgBox('Key exists!!', mbInformation, MB_OK);
end;

for this example, it works, I have the message box, but with this it doesn't:

if RegKeyExists(HKEY_LOCAL_MACHINE, 'Software\Autodesk\Maya') then
begin
  MsgBox('Key exists!!', mbInformation, MB_OK);
end;

But the Maya key exists on my computer. Can anybody help me?

EDIT :

In fact, it seems that Inno Setup don't access to the right keys...
For example, with this code I list all the subkeys of HKEY_LOCAL_MACHINE\SOFTWARE, but (!) the result is all subkey of HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node ...

if RegGetSubkeyNames(HKEY_LOCAL_MACHINE, 'SOFTWARE', Names) then
begin
  S := '';
  for I := 0 to GetArrayLength(Names)-1 do
    S := S + Names[I] + #13#10;
  MsgBox('List of subkeys:'#13#10#13#10 + S, mbInformation, MB_OK);
end;

Why this Wow6432Node key?

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
John Lev
  • 211
  • 1
  • 2
  • 6

3 Answers3

23

It's not Inno Setup's fault at all; the Registry is virtualized in Vista and higher, and on 64-bit there are branches for native 64-bit and WOW'ed 32-bit.

In this case, since Inno Setup is a 32-bit program, the OS directs all of its HKLM\Software registry requests to the WOW6432Node.

To handle the registry virtualization in your installer, you can specifically use x86 and x64 key roots. For example, use HKLM32 or HKLM64 in your [Registry] section when you need to differentiate. In [Code] section, wrap registry helper function calls using HKLM64 in an if IsWin64 block.

This example works ok from our installer, whether or not the installer is declared as an x64 installer.

function Mobu120x64IsAvailable(): Boolean;
var
  resultString: String;
begin
  resultString := 'No';
  if IsWin64 then
  begin
    Result := RegValueExists(HKLM64, 'SOFTWARE\Autodesk\MotionBuilder\2012', 'InstallPath');
    if Result then begin
      resultString := 'Yes';
    end;
    Log('Win64: Found Mobu 12.0 for x64?:' + resultString);
  end;
end;
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
Epu
  • 615
  • 8
  • 18
  • The key sentence there: "The values may have a suffix of 32 or 64. Root key values with a suffix of 32 (for example, HKLM32) map to the 32-bit view of the registry; root key values with a suffix of 64 (for example, HKLM64) map to the 64-bit view of the registry." – Epu Feb 07 '13 at 05:30
18

Let me guess... you're on Windows 7 64-bit?

It's not InnoSetup's fault at all, it's that the Registry is virtualized in Vista & higher, and on 64-bit there are branches for native 64-bit and WOW'ed 32-bit.

In this case, since InnoSetup is a 32-bit program, the OS directs all of its HKLM\Software Registry requests to the WOW6432Node.

If your program is 64-bit, then you want to use a 64-bit setup program too.

ewall
  • 27,179
  • 15
  • 70
  • 84
  • Yes thank you it's my problem ! But i need to make an installer that works on 32 and 64bits. It's just a plugin for Maya (3D Software) independant of architecture. But Maya can be 32 or 64bits and i need to know that for copying my files in the right folder. If i use a x64 installer, it won't work on x86, but i doesn't want to make 2 installers. a solution to bypass the WOW6432Node link without making a x64 installer ? – John Lev Oct 27 '10 at 15:55
  • 4
    Hmm... I've never had to build an x64 package with InnoSetup myself. But the help docs include several references on [32- vs 64-bit](http://www.jrsoftware.org/ishelp/index.php?topic=32vs64bitinstalls) and [limitations of 64-bit installs](http://www.jrsoftware.org/ishelp/index.php?topic=64bitlimitations) that help clarify what is effected by redirection and what isn't. But first you probably need to enable 64-bit mode by setting [ArchitecturesInstallIn64BitMode to "x64"](http://www.jrsoftware.org/ishelp/index.php?topic=setup_architecturesinstallin64bitmode)... – ewall Oct 27 '10 at 17:24
  • 1
    @ewall: I recommend putting those Inno help links in your actual answer rather than just the comments. – Oliver Giesen Oct 28 '10 at 08:25
  • 1
    Unless you've written a 64-bit plug-in, you *don't* need a 64-bit installer, @John. A 64-bit program (such as Maya) cannot use 32-bit plug-ins, so it's OK if your 32-bit installer cannot detect the presence of 64-bit Maya — the thing you're installing wouldn't work there anyway. – Rob Kennedy Oct 28 '10 at 22:01
  • I just had this problem with motion builder 2012 x64. If I do: `[Setup] ArchitecturesInstallIn64BitMode=x64` it finds the keys ok, but then the x86 keys it needs to find are not found. The documentation for EnableFsRedirection include a sample to flip the mode back temporarily to x86 mode. You can't enable x64 mode using the example code if you didn't start in an x64 mode. – Epu Jun 10 '11 at 19:12
  • The EnableFsRedirection doesn't enable registry redirection though. – Epu Jun 13 '11 at 15:54
1

Are you sure that Software\Autodesk\Maya is a registry key? Maybe it's just a value and you have to use RegValueExists.

splash
  • 13,037
  • 1
  • 44
  • 67