首先,在[setup]段增加如下内容:
[Setup]
; Tell Windows Explorer to reload the environment
ChangesEnvironment=yes
Inno Setup更改环境变量在[Register]代码段
[Registry]
Root: HKCU; Subkey: "Environment"; ValueType:string; ValueName: "VARIABLE_NAME"; ValueData: "new_value"; Flags: preservestringtype
上述代码可以更改用户变量
[Registry]
Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; ValueType: string; ValueName: "VARIABLE_NAME"; ValueData: "new_value"; Flags: preservestringtype
上述代码可以更改系统变量
其中:VARIABLE_NAME表示变量名,new_value表示变量值。
如果变量值是安装后的程序内部路径,new_value可以写成{app}\后接文件名,{app}表示安装路径。
参考资料:Inno Setup FAQhttps://jrsoftware.org/isfaq.php#envinstallation - How to set a global environment variable from Inno Setup installer? - Stack Overflow
https://stackoverflow.com/questions/25289056/how-to-set-a-global-environment-variable-from-inno-setup-installer