Inno Setup questions about environment variables and UAC elevation - inno-setup

I have two problems with INNO Setup?
How do I check if an env. variable exists and has a value? (I'm interested in %VS90COMNTOOLS%)
How do I run the installer with elevated rights? (Display the UAC window and ask for more rights)
Thanks

For 1, you can use the built-in Pascal script and the API function GetEnvironmentVariable() documented via MSDN.
For 2, name your executable Setup.exe, or use the [Setup] section's PrivilegesRequired entry as documented in InnoSetup's FAQ page.

Related

Using RegQueryStringValue with Inno Setup 6.0.0 and HKCU. GetPathInstalled [duplicate]

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 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:
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
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.
or using {user*} constants.
Though these are not reliable, at least for these reasons:
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.
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:
for files: Inno Setup Create individual shortcuts on all desktops of all users
for registry: Uninstall auto-run registry entries for all users
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?
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
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:
Inno Setup - Register components as an administrator
Inno Setup - Access unprivileged account folders from installer that requires privileges
If you want to prevent user from breaking this by explicitly running the installer with Administrator privileges, see
Can't get Inno Setup postinstall Run item to runasoriginaluser or
my answer to How to write to the user's My Documents directory with installer when the user used 'Run As Administrator'.
Or you can programmatically find out, what is the account of the current Windows logon session:
Determine if Administrator account that runs elevated Inno Setup installer is the same as the account of the current Windows logon session.
Another option is to allow the installer to install for the current user only:
Make Inno Setup installer request privileges elevation only when needed

programmatically pin to quick access for another (or all) user [duplicate]

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 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:
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
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.
or using {user*} constants.
Though these are not reliable, at least for these reasons:
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.
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:
for files: Inno Setup Create individual shortcuts on all desktops of all users
for registry: Uninstall auto-run registry entries for all users
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?
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
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:
Inno Setup - Register components as an administrator
Inno Setup - Access unprivileged account folders from installer that requires privileges
If you want to prevent user from breaking this by explicitly running the installer with Administrator privileges, see
Can't get Inno Setup postinstall Run item to runasoriginaluser or
my answer to How to write to the user's My Documents directory with installer when the user used 'Run As Administrator'.
Or you can programmatically find out, what is the account of the current Windows logon session:
Determine if Administrator account that runs elevated Inno Setup installer is the same as the account of the current Windows logon session.
Another option is to allow the installer to install for the current user only:
Make Inno Setup installer request privileges elevation only when needed

How to make installation default path to user desktop with Inno Setup

I'm using Inno setup for make a installation to my program.
And I would like to know, how to make the program to be installed in the user desktop by default?
I figured out, I need to use DefaultDirName=.
I need to know, what to write there for install to be on user desktop be default.
Any help?
Use {userdesktop} constant:
[Setup]
DefaultDirName={userdesktop}
You may also consider setting PrivilegesRequired to lowest, as you probably do not need the installer to run with Administrator privileges.
[Setup]
PrivilegesRequired=lowest

Inno Setup: is it a script based deployment program?

I am using Inno Setup for the first time. When I start the program I am presented with a blank script page. Is scripting the only way you can create a setup package? Is there anything else?
Yes, Inno Setup is script-based (thank God -- this really makes things a lot easier if you ask me). But there is a "wizard" that lets you create a new setup by a simple step-by-step approach in a simple GUI. Simply choose "Create a new script file using the Script Wizard" in the "Welcome" dialog box that appears when you start the Inno Setup Compiler.
If you have disabled the Welcome dialog box, use File/New instead to start the wizard.
Update
I was just informed about the new InnoIDE.
Inno Setup is script based. If you want a GUI Builder then you may check the site "Third-Party Files" on Inno Setups Homepage.
The easiest way to start is with one of the example scripts included with the install.
Just change the product name in the sample and you are set for 90% of basic installs

INNO: Disallow "Ignore" when file is in use

I am using Inno Setup for the installer for my windows application. If a user has the application when the installer is run (eg. for an update), the installer will stop when it is unable to replace a file in use, and it allows the user to select whether to Abort, Ignore, or Retry.
I would like it to only allow Abort or Retry and remove the option to Ignore. Does anyone know how this can be done?
Or if this can't be done, how can I make the installer abort if the application is running?
The easy way to detect whether the application is running requires co-operation from the application, so it's best to work this out before you ship your first version. Use Inno Setup's AppMutex setting. There is an example in the Inno Setup knowledge base for setting up a mutex visible in multiple sessions. There is more about AppMutex in Inno Setup's help file.

Resources