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

如何在Inno Setup的INI文件中写入无盘符安装路径

解决Inno Setup中INI路径移除盘符的问题

问题场景

当前Inno Setup的[INI]段配置如下:

[INI]
Filename: "{app}\\game.ini"; Section: "Nancy Data"; Key: "CDDrive1";  \\
  String: "{drive:{src}}\\"; Flags: createkeyifdoesntexist
Filename: "{app}\\game.ini"; Section: "Nancy Data"; Key: "CDDrive2"; \\
  String: "{drive:{src}}\\"; Flags: createkeyifdoesntexist
Filename: "{app}\\game.ini"; Section: "Nancy Data"; Key: "HDDrive"; \\
  String: "{drive:{src}}"; Flags: createkeyifdoesntexist
Filename: "{app}\\game.ini"; Section: "Nancy Data"; Key: "IDPath"; \\
  String: "{app}\\Нэнси Дрю. Секреты могут убивать"; Flags: createkeyifdoesntexist
Filename: "{app}\\game.ini"; Section: "Nancy Data"; Key: "CifTreePath"; \\
  String: "{app}\\Нэнси Дрю. Секреты могут убивать\\ciftree\\"; \\
  Flags: createkeyifdoesntexist

生成的INI文件中,IDPath和CifTreePath会自动带上盘符:

[Nancy Data]
CDDrive1=C:
CDDrive2=C:
HDDrive=C:
IDPath=C:\\Program Files (x86)\\My Program\\Нэнси Дрю. Секреты могут убивать
CifTreePath=C:\\Program Files (x86)\\My Program\\Нэнси Дрю. Секреты могут убивать\\ciftree\\

需要实现无盘符的路径写入。

解决方案

利用Inno Setup内置的{pathwithoutdrive:...}常量,该常量会自动剥离路径中的盘符部分。只需修改[INI]段中对应行的{app}为{pathwithoutdrive:{app}}即可:

[INI]
Filename: "{app}\\game.ini"; Section: "Nancy Data"; Key: "CDDrive1";  \\
  String: "{drive:{src}}\\"; Flags: createkeyifdoesntexist
Filename: "{app}\\game.ini"; Section: "Nancy Data"; Key: "CDDrive2"; \\
  String: "{drive:{src}}\\"; Flags: createkeyifdoesntexist
Filename: "{app}\\game.ini"; Section: "Nancy Data"; Key: "HDDrive"; \\
  String: "{drive:{src}}"; Flags: createkeyifdoesntexist
Filename: "{app}\\game.ini"; Section: "Nancy Data"; Key: "IDPath"; \\
  String: "{pathwithoutdrive:{app}}\\Нэнси Дрю. Секреты могут убивать"; Flags: createkeyifdoesntexist
Filename: "{app}\\game.ini"; Section: "Nancy Data"; Key: "CifTreePath"; \\
  String: "{pathwithoutdrive:{app}}\\Нэнси Дрю. Секреты могут убивать\\ciftree\\"; \\
  Flags: createkeyifdoesntexist

可选调整

如果不需要路径开头的反斜杠,可以结合{trimleft:...}进一步处理,将String部分修改为:

String: "{trimleft:{pathwithoutdrive:{app}},1}\\Нэнси Дрю. Секреты могут убивать"; Flags: createkeyifdoesntexist

最终生成的路径会变为Program Files (x86)\\My Program\\Нэнси Дрю. Секреты могут убивать。

内容的提问来源于stack exchange,提问作者livingsamurai

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.03 23:11:13