How to write the "My Documents" directory with the installer when the user used "Run as administrator",

I have a program that should create files in the My Document directory during installation. This is a strict fixed requirement, it does not change. The problem is that if the user runs "Run as administrator" in the installation file, innosetups constant {userdocs} points to the directory of the administrator document, and not to the registered user.

So, Googled and found this:

Install the files in the My Documents folder of the original user through Inno Setup in Windows Vista / 7

The answer is incorrect, however, since innosetup even claims that

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.

I assume that I can recommend the user not to use Run As Administrator, but I do not know how to prevent him from rising.

I thought that perhaps the program itself installed the My Documents \ Program directory on first launch (after installation). Will this work? He will have to copy files from the directory of his program files as a potentially limited user. Is it possible, or will I run into problems in priveleges?

+6
source share
3 answers

The answer to the original is valid but not recommended. When the installation is started, RunAsOriginalUser will be started as the user who is currently logged into Windows. This is done by the fact that part of the installation launch is not activated, and then another copy is launched, which is added for the actual installation.

When the user explicitly performs “Run as administrator”, the “unelevated stub” is also launched, in which case nothing can be done to configure access to the original user, since this information has already been replaced.

The accepted practice is to perform any specific work with the profile in the application itself, as you suggested, which also means that it will work for other users and in the LUA environment in pre Vista (where you would have the same situation that and now you are watching).

+5
source

First, make sure that the installer will not require privilege escalation by setting PrivilegesRequired=lowest :

 [Setup] PrivilegesRequired=lowest 

To abort the installer when the installer explicitly launches "As Administrator" by the user, in Windows Vista and earlier versions use the IsAdmin function (or IsAdminInstallMode or IsAdminLoggedOn [in older versions]) in InitializeSetup :

 [Code] function InitializeSetup(): Boolean; begin Result := True; if (GetWindowsVersion >= $05010000) and IsAdmin then begin MsgBox('Do not run this installer "As Administrator".', mbError, MB_OK); Result := False; end; end; 

For more information on this topic, see " Installing Files in the My Documents Folder of the Original User Using the Inno Installer on Windows Vista / 7" .

+1
source

This article may provide some guidelines for working on elevation,

http://www.codeproject.com/Articles/18946/High-elevation-can-be-bad-for-your-application-How

In general, this gives you the opportunity to execute an executable file (which creates files in the My Documents section) at the end of the installation without raising it.

0
source

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


All Articles