windows - 根据安装程序是处于用户模式还是管理员模式更改环境注册表项
问题描述
如果用户以管理员模式运行安装程序,则应修改系统路径,如果安装程序以用户模式运行,则需要修改用户环境变量。
[Registry]
; If user installation mode
#define EnvironmentRootKey "HKCU"
#define EnvironmentKey "Environment"
; If admin mode
#define EnvironmentRootKey "HKLM"
#define EnvironmentKey "System\CurrentControlSet\Control\Session Manager\Environment"
Root: {#EnvironmentRootKey}; Subkey: "{#EnvironmentKey}"; ValueType: expandsz; \
ValueName: "Path"; ValueData: "{olddata};{app}\bin"; Tasks: addtopath; \
Check: NeedsAddPath(ExpandConstant('{app}\bin'))
如果安装程序处于用户模式和管理员模式,我知道HKA
会自动解析,但.HKCU
HKLM
EnvironmentKey
基本上是这样的:
#if "HKA" == "HKCU"
#define EnvironmentKey "Environment"
#else
#define EnvironmentKey "System\CurrentControlSet\Control\Session Manager\Environment"
#endif
解决方案
使用脚本常量:
[Registry]
Root: HKA; Subkey: "{code:GetEnvironmentKey}"; ...
[Code]
function GetEnvironmentKey(Param: string): string;
begin
if IsAdminInstallMode then
Result := 'System\CurrentControlSet\Control\Session Manager\Environment'
else
Result := 'Environment';
end;
推荐阅读
- mariadb - 如何让 Debezium 自动切换到下一个 binlog
- fortran - 使用指针创建链表时出现“Fortran 运行时错误:文件结尾”问题(在 DO 循环中读取)
- mysql - 通过 Django ORM 在 MySQL 中的非二进制 LIKE
- java - 如何让我的线程按顺序运行?
- flutter - 为什么在颤振中使用 TabBar 时缺少 TabController
- java - 如何在具有多个 firebase 项目的一个应用程序中设置 firebase crashltycs
- python - 如何修复“RuntimeError: dataset.__iter__() 仅在启用急切执行时受支持。”
- c# - 如何根据条件将 Line Item 行合并到上述行
- python - 如何检查 PDF 是扫描图像还是包含文本
- java - 如何在多个 Mono 运算符中重用变量?