Inno setup Using {localappdata} for a registered user

I am trying to create an installer using Inno Setup, when I encounter this problem, everything else is installed, but the registry keys are not installed by the current user. I found this useful topic (thank you very much!):
Inno Setup Create a registry key for logging in (not for the administrator user)

This solved the part for adding registry keys, for example:

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

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

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

Requires: 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 administrative temperature (of course)

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

runasoriginaluser

Valid only in the [Run] section. If this flag is specified and the system is running Windows Vista or later, the spawned process will execute with (usually not elevated) user credentials that the installation originally started (that is, the "pre-UAC dialog" credentials).

This is the default behavior when using the postinstall flag.

If the user starts the installation program by right-clicking its EXE file and selecting "Run as administrator", this flag, unfortunately, will not be because the installation program does not have the ability to run any code using the user's original credentials. The same is true if the installer is running with an already elevated process. Please note, however, that this is not an Inno Installation Restriction; Installers on the Windows installer cannot return the original user credentials either in such cases.

This flag cannot be combined with the runascurrentuser flag.

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

+1
source share
1 answer

Firstly, your approach is wrong.

There are two correct ways:

  • If the installer installs the application only for the current (unprivileged) user, it does not require administrator rights. Use PrivilegesRequired=lowest .

     PrivilegesRequired=lowest 

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

  • If the installer installs the application for all users, it makes no sense to update the registry of one specific user. All users need registry settings, not just one. In this case, the recommended approach is to set the general registry settings in HKLM (or save the settings to some shared file). And ask the application to copy the settings to the user registry bush on first launch.

    See also How to write the user with the installer to the My Documents folder when the user used Run as Administrator .

You can also allow the user to choose between these two approaches.
See Make Inno Setup Installer Request Privilege Changes Only If Required .

For similar issues, see


In either case, the constant {localappdata} resolved by the Inno installation process, running in the context of the administrator account. And the resolution does not affect the runasoriginaluser flag.

But you can use the equivalent environment variable %LOCALAPPDATA% , which will be allowed by the executable process, that is, in the context of the "source user".

To allow the change of environment variables, you need to run 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 

For another approach, see Inno Setup - Accessing unprivileged account folders from an installer that requires privileges .

0
source

Source: https://habr.com/ru/post/915359/


All Articles