You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.19 17:36:24