Inno Setup doesn't allow access to all registry keys, why?

[亡魂溺海] 提交于 2019-11-30 07:55:03

问题


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?


回答1:


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;



回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/4033976/inno-setup-doesnt-allow-access-to-all-registry-keys-why

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!