INNOSETUP 操作注册表 重定向至Wow6432Node问题
实际上问题就出在Win64上。Windows 32bit和64bit版本的注册表稍微有不同。我们知道64bit系统上照样可以跑32bit的程序,因此在注册表上也有区分,特意为32bit程序作了兼容处理。32bit程序对注册表HKEY_LOCAL_MACHINE根下的项目操作都进行了重定向:读取HKEY_LOCAL_MACHINE\SOFTWARE下的键值都会重定向到HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\<company>\<product>。那么这就很好解释了,Premiere Pro目前只能运行在64Bit系统上,因此在Wow6432Node下是不会存在记录的,读取相应键值自然会失败。
function GetInstallString(): String; var sInstallPath: String; begin sInstallPath := 'C:\Program Files\Adobe\Common\Plug-ins\7.0\MediaCore'; if RegValueExists(HKLM64, 'SOFTWARE\Adobe\Premiere Pro\CurrentVersion', 'Plug-InsDir') then begin RegQueryStringValue(HKLM64, 'SOFTWARE\Adobe\Premiere Pro\CurrentVersion', 'Plug-InsDir', sInstallPath) end Result := sInstallPath; end;
通过HKLM32和HKLM64明确指出读取的具体位置,就可以避免上述这种问题了。事实上,在inno setup的说明文档中还有另外一种方法可以尝试,也可以避免64bit系统产生的问题。具体代码:
var OldState: Boolean; ResultCode: Integer; begin // First verify that the user is running a supported 64-bit version // of Windows, because calling EnableFsRedirection(False) will // raise an exception otherwise. if IsWin64 then begin // Turn off redirection, so that cmd.exe from the 64-bit System // directory is launched. OldState := EnableFsRedirection(False); try Exec(ExpandConstant('{cmd}'), '', '', SW_SHOW, ewWaitUntilTerminated, ResultCode); finally // Restore the previous redirection state. EnableFsRedirection(OldState); end; end; end;
关键就是通过调用EnableFsRedirection()函数来禁用注册表操作转发行为。在调用之前先判断当前安装程序是否是运行在64位系统上。
Update 2016-3-7:
在64Bit系统上,将动态库文件拷贝到C:\WINDOWS\System32目录下时,会自动重定向到SysWOW64目录下,导致程序运行异常。这事可以通过设置在[Files]段设置Flags:64即可禁用目录重定向(参考链接)。
参考:https://www.cnblogs.com/csuftzzk/p/innosetup_read_registry.html
本文探讨了InnoSetup在64位Windows系统中遇到的注册表重定向问题,并提供了两种解决方案:一是通过指定HKLM32和HKLM64来明确读取位置;二是使用EnableFsRedirection()函数来禁用注册表操作转发行为。


403

被折叠的 条评论
为什么被折叠?



