使用{localappdata}登录用户的Inno设置 [英] Inno Setup Using {localappdata} for logged in user

查看:212
本文介绍了使用{localappdata}登录用户的Inno设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

遇到此问题时,我正在尝试使用Inno Setup创建安装程序,正在安装所有其他程序,但是当前用户中未安装注册表项.我发现了这个有用的主题(非常感谢!):
Inno设置为登录创建注册表项用户(不是管理员用户)

I'm trying to create an installer using Inno Setup when I encounter this problem, everything else is being installed, but the registry keys are not being installed in the current user. I found this helpful topic (many thanks!):
Inno Setup Creating registry key for logged in user (not admin user)

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

This solved the part for adding registry keys, like this:

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

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

My problem:
{localappdata} refers to the admin user (admin) not the local user (test):

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

It added: HKCU\Software\myprinter OutputFile REG_SZ c:\users\admin\appdata\local\temp\

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

Is required: HKCU\Software\myprinter OutputFile REG_SZ c:\users\test\appdata\local\temp\

该软件无法运行,因为(当然)不允许使用管理临时用户

The software does not work because it is not allowed to use the admin temp (of course)

尽管根据联机帮助,它应该对启动安装程序的用户有效,但就我而言,似乎不起作用. (带有或不带有postinstall标志)

Although according to the online help it should work for the user that started the setup, it seems it does not, in my case. (with or without the postinstall flag)

runasoriginaluser

仅在[运行]部分有效.如果指定了此标志并且 系统运行的是Windows Vista或更高版本,则生成的进程将 使用用户的(通常是非提升的)凭据执行 最初启动安装程序(即"UAC之前的对话框"凭据).

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).

这是使用postinstall标志时的默认行为.

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

如果用户通过右键单击其EXE文件并选择来启动安装程序 以管理员身份运行",那么不幸的是,此标志将没有 效果,因为安装程序没有机会使用 原始用户凭据.如果从安装程序启动安装程序也是如此 已经升高的过程.但是请注意,这不是Inno 特定于设置的限制;基于Windows Installer的安装程序无法 在这种情况下,都将返回到原始用户凭据.

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.

此标志不能与runascurrentuser标志结合使用.

This flag cannot be combined with the runascurrentuser flag.

注意:运行Inno安装程序:5.5.9(a)和Windows 10

Note: running Inno Setup: 5.5.9 (a) and Windows 10

推荐答案

首先,您的方法不正确.

First, your approach is not correct.

有两种正确的方法:

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

PrivilegesRequired=lowest

然后{localappdata} 常量(和类似名称)将正确引用到当前用户的文件夹.

Then the {localappdata} constant (and similar) will correctly refer to the current user's folder.

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

If the installer installs the application for all users, it does not make sense to update registry of one specific users. All users need the registry settings, not just the one. In this case the recommended approach is to set common registry settings in HKLM (or store the settings to some common file). And have the application copy the settings to the user registry hive on the first run.

另请参见如何在用户使用以管理员身份运行"时使用安装程序写入用户的我的文档"目录.

您还可以允许用户在这两种方法之间进行选择.
请参见仅在需要时使Inno Setup安装程序请求特权提升.

You can also allow the user choose between these two approaches.
See Make Inno Setup installer request privileges elevation only when needed.

有关类似问题,请参见

  • Inno Setup - puts user files in admin documents
  • Inno Setup always installs into admin's AppData directory

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

Anyway, the {localappdata} constant is resolved by the Inno Setup process, running within the Administrator account context. And the resolving is in no way affected by the runasoriginaluser flag.

但是您可以使用等效的%LOCALAPPDATA%环境变量,该变量将由执行的过程来解析,即在原始用户"上下文中.

But you can use an equivalent %LOCALAPPDATA% environment variable, which will be resolved by the executed process, i.e within the "original user" context.

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

To allow environment variables resolution, you need to execute the command through 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设置-从需要特权的安装程序访问非特权帐户文件夹.

这篇关于使用{localappdata}登录用户的Inno设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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