gpt4 book ai didi

inno-setup - Inno Setup 使用 {localappdata} 登录用户

转载 作者:行者123 更新时间:2023-12-04 14:28:39 26 4
gpt4 key购买 nike

当我遇到这个问题时,我正在尝试使用 Inno Setup 创建安装程序,正在安装其他所有内容,但当前用户未安装注册表项。我找到了这个有用的主题(非常感谢!):
Inno Setup Creating registry key for logged in user (not admin user)

这解决了添加注册表项的部分,如下所示:

 [Run]
Filename: reg.exe; \
Parameters: "ADD ""HKCU\Software\myprinter"" /v OutputFile /t REG_SZ /d ""{localappdata}\temp\\"""; \
Flags: runasoriginaluser runhidden

我的问题:
{localappdata}指的是管理员用户(admin)不是本地用户(test):

它添加了:HKCU\Software\myprinter OutputFile REG_SZ c:\users\admin\appdata\local\temp\

是必需的:HKCU\Software\myprinter OutputFile REG_SZ c:\users\test\appdata\local\temp\

软件不工作是因为不允许使用admin temp(当然)

虽然根据联机帮助,它应该适用于启动设置的用户,但在我的情况下似乎并非如此。 (有或没有 postinstall 标志)

runasoriginaluser

Valid only in a [Run] section. If this flag is specified and the system is running Windows Vista or later, the spawned process will execute with the (normally non-elevated) credentials of the user that started Setup initially (i.e., the "pre-UAC dialog" credentials).

This is the default behavior when the postinstall flag is used.

If a user launches Setup by right-clicking its EXE file and selecting "Run as administrator", then this flag, unfortunately, will have no effect, because Setup has no opportunity to run any code with the original user credentials. The same is true if Setup is launched from an already-elevated process. Note, however, that this is not an Inno Setup-specific limitation; Windows Installer-based installers cannot return to the original user credentials either in such cases.

This flag cannot be combined with the runascurrentuser flag.

注意:运行 Inno Setup:5.5.9 (a) 和 Windows 10

最佳答案

首先,你的做法不对。

正确的做法有两种:

  1. 如果安装程序仅为当前(非特权)用户安装应用程序,则不需要管理员权限。使用 PrivilegesRequired=lowest .

     PrivilegesRequired=lowest

    然后是 {localappdata} constant (和类似的)将正确引用当前用户的文件夹。

  2. 如果安装程序为所有用户安装应用程序,则更新某个特定用户的注册表没有意义。所有用户都需要注册表设置,而不仅仅是一个。在这种情况下,推荐的方法是在 HKLM 中设置通用注册表设置(或将设置存储到某个通用文件中)。并让应用程序在第一次运行时将设置复制到用户注册表配置单元。

    另见 How to write to the user's My Documents directory with installer when the user used 'Run As Administrator' .

您还可以让用户在这两种方法之间进行选择。
参见 Make Inno Setup installer request privileges elevation only when needed .

这个问题从更广泛的角度涵盖了这个主题:
Installing application for currently logged in user from Inno Setup installer running as Administrator

类似问题见


无论如何,{localappdata} 常量由在管理员帐户上下文中运行的 Inno Setup 进程解析。而且解析绝不会受到 runasoriginaluser 标志的影响。

但是您可以使用等效的 %LOCALAPPDATA% 环境变量,它将由执行的进程解析,即在“原始用户”上下文中。

要允许环境变量解析,需要通过cmd.exe执行命令。

[Run]
Filename: {cmd}; \
Parameters: "/C reg.exe ADD ""HKCU\Software\myprinter"" /v OutputFile /t REG_SZ /d ""%LOCALAPPDATA%\temp\\"""; \
Flags: runasoriginaluser runhidden

虽然这是不真实的。


另一种方法,请参阅 Inno Setup - Access unprivileged account folders from installer that requires privileges .

关于inno-setup - Inno Setup 使用 {localappdata} 登录用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40613608/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com