从以管理员身份运行的 Inno Setup 安装程序为当前登录的用户安装应用程序 [英] Installing application for currently logged in user from Inno Setup installer running as Administrator

查看:18
本文介绍了从以管理员身份运行的 Inno Setup 安装程序为当前登录的用户安装应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

关于创建 (Inno Setup) 安装程序的一个非常常见的问题是从以提升的/管理员权限运行的安装程序访问/修改特定用户(当前登录的用户)的配置文件.

A very common question about creating (Inno Setup) installers revolves around accessing/modifying a profile of a specific user (the currently logged in user) from an installer that runs with elevated/Administrator privileges.

这样做有很多缺点并且容易出错.

Doing this has many drawbacks and is error prone.

所有现有答案都涵盖了部分问题(注册表、文件、桌面图标等).这个问题的目的是收集解决全球问题的答案,使用所有可能的方法.

All the existing answers cover part of the problem (registry, files, desktop icon, etc). A purpose of this question is to collect answers that address the problem globally, with all possible approaches.

推荐答案

Inno Setup 没有任何内置机制来从以提升/管理员权限运行的安装程序访问或修改用户环境.

Inno Setup does not have any built-in mechanism to access or modify user environment from installer running with elevated/Administrator privileges.

实现这一目标的所有尝试都依赖于以下技巧:

All the attempts to achieve this rely on tricks like:

  • runasoriginaluser flag or ExecAsOriginalUser function. Some examples:

修改或访问登录用户的注册表:
Inno Setup 为登录用户(非管理员用户)创建注册表项
如何从以管理员身份运行的 Inno Setup 安装程序中读取登录用户的注册表 HKCU

Modifying or accessing registry of logged in user:
Inno Setup Creating registry key for logged in user (not admin user) or
How to read registry HKCU for logged In user from Inno Setup installer running as administrator

访问登录用户的AppData文件夹:
Inno Setup 始终安装到管理员的 AppData 目录中
使用{localappdata}登录用户的Inno Setup
Inno Setup - 将用户文件放入管理文档.

Accessing AppData folder of logged in user:
Inno Setup always installs into admin's AppData directory or
Inno Setup Using {localappdata} for logged in user or
Inno Setup - puts user files in admin documents.

或使用 {user*} 常量.

尽管这些并不可靠,但至少出于以下原因:

Though these are not reliable, at least for these reasons:

  • 当当前用户没有管理员权限时,他需要在安装程序 UAC 提示中输入管理员凭据.这会将安装程序切换到不同的用户.所以 {user*} 常量不会指代启动安装的用户.

  • When the current user does not have Administrator privileges, (s)he needs to enter Administrator credentials on installer UAC prompt. That switches the installer to a different user. So {user*} constants will not refer to the user that initiated the installation.

当用户以提升的权限显式运行安装程序时,例如通过右键单击安装程序并选择 以管理员身份运行" 或从另一个提升的应用程序(文件管理器)、runasoriginaluser 标志或 的原始用户"运行它>ExecAsOriginalUser 函数已经被提升.

When the user explicitly runs the installer with elevated privileges, e.g. by right-clicking the installer and selecting "Run as administrator" or running it from another elevated application (file manager), the "original user" for runasoriginaluser flag or ExecAsOriginalUser function will already be elevated.

在企业环境中,应用程序由管理员安装,管理员不是将使用应用程序的用户.

In corporate environments, applications are installed by Administrator, who is not the user that will be using the application.

此问题唯一正确的通用解决方案是仅将用户环境的设置推迟到实际用户会话.

The only correct generic solution to this problem is to defer a setup of the user environment only to the actual user session.

最简单的方法是让应用程序自己在第一次运行时进行设置.

Easiest is to have the application itself do the setup on its first run.

安装程序只能部署应用程序可用于安装的共享文件.

The installer can only deploy shared files that the application can use for the setup.

如果您因任何原因无法修改应用程序,则必须迭代所有帐户并修改它们:

If you cannot modify the application for whatever reason, you would have to iterate all accounts and modify them:

如果您需要确保将设置分发到仅在安装后创建的帐户,请参阅如何为每个用户安装文件,包括未来的新用户,在 Inno Setup 中?

If you need to make sure the settings get distributed to accounts that get created only after installation, see How to install files for each user, including future new users, in Inno Setup?

如果您对仅为登录用户设置应用程序这一事实感到满意,请使用 PrivilegesRequired=lowest:

If you are happy with a fact that the application will be setup for the logged in user only, use PrivilegesRequired=lowest:

[Setup]
PrivilegesRequired=lowest

然后 {user*} 常量将正确引用当前用户的文件夹.

Then the {user*} constants will correctly refer to the current user's folder.

如果安装的某些子任务仍然需要管理员权限,您可以只为子任务请求权限提升:

If you still need Administrator privileges for some sub-task of the installation, you can requests privileges elevation for the sub-task only:

如果您想通过以管理员权限显式运行安装程序来防止用户破坏这一点,请参阅

If you want to prevent user from breaking this by explicitly running the installer with Administrator privileges, see

或者你可以通过编程方式找出当前Windows登录会话的帐户是什么:

Or you can programmatically find out, what is the account of the current Windows logon session:

这篇关于从以管理员身份运行的 Inno Setup 安装程序为当前登录的用户安装应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆