Inno Setup如何自动替换安装路径中的特殊字符?
解决Inno Setup读取注册表路径时的字符替换问题
修改后的代码
[Setup] DefaultDirName={code:GetInstallationPath} [Code] var InstallationPath: string; function GetInstallationPath(Param: string): string; begin { Detected path is cached, as this gets called multiple times } if InstallationPath = '' then begin if RegQueryStringValue( HKLM64, 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Steam App 1580780', 'InstallLocation', InstallationPath) then begin { 替换路径中的错误字符 } InstallationPath := StringReplace(InstallationPath, 'Σ', 'Σ', [rfReplaceAll]); Log('Detected and corrected Steam installation: ' + InstallationPath); end else begin InstallationPath := 'C:\games'; Log('No installation detected, using the default path: ' + InstallationPath); end; end; Result := InstallationPath; end;
关键修改说明
- 在成功读取注册表中的安装路径后,调用Inno Setup内置的
StringReplace函数,将路径中的错误字符Σ全局替换为正确的Σ - 更新日志输出内容,明确记录路径已修正的操作
内容的提问来源于stack exchange,提问作者Hunter_ARG
相关产品推荐
相关产品推荐

