force inno setup to store data in HKCU with PrivilegesRequired=lower - inno-setup

When Inno Setup configured with PrivilegesRequired=admin, it stores uninstall registry key in HKEY_LOCAL_MACHINE.
How can i force to store uninstall registry key in HKEY_CURRENT_USER?

As your title said, you need to use PrivilegesRequired=lowest. Anything other than that, and the "local user" may not be what you expect.
If the setup needs admin permissions to remove the old setup, you can use ShellExec, making sure that the application you're calling as the admin manifest, or you pass the "runas" verb.

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

Request admin privileges during un-installation

I'm writing some values to HKLM during the installation of my application.
I'm using the PrivilegesRequired=admin flag in my installer, so during the installation, writing to the registry works fine.
However, when I un-install my application, Inno Setup doesn't request admin privileges, so my call to RegDeleteKeyIncludingSubkeys fails.
I would like to ask if it's possible to make it so that Inno Setup requires admin privileges at un-installation as well.
Thank you very much.
Edit: I've read that the uninstaller should contain this information, but for me, it doesn't. I don't even remember how I created the uninstaller...
I found the problem myself:
I forgot to sign the uninstaller.
The Windows Programs & Features uninstaller requires that uninstaller have to be signed.
Once I signed the uninstaller, everything would work as expected.

How to clean up registry settings with uninstall?

I have an installer which needs to add a key to Currentuser under \Software\Microsoft\Office\12.0\Excel\Options. It must be CurrentUser because excel does not look in LocalMachine. I have a customer that requires Admin rights for an install. I found that when the installer was run as the Admin user, the key was created under the Admin users registry settings. To get around this, I wrote a custom action which created the Excel key in Currentuser, and then copied the key to every other user currently logged on to the machine. This seems to work.
The problem i now have is on the uninstall. The registry key is left in place, which causes issues with Excel. What is the best way to get rid of this registry key on an uninstall?
I am using the Windows installer in VS 2010.
Currie
try installing and running Revo Uninstaller. Once it's installed, see if excel is still there to be uninstalled. In REVO, there is a step in the uninstall process where you check the checkboxes, in bold text, of the registry items to be deleted.
http://www.bleepingcomputer.com/download/revo-uninstaller/
(on the site, click "download Now" instead of the "download" button at the top (which is just a link to google leads).

Can't seem to load a managed dll from Installer during setup?

I'm developing an installer for an application which includes a Windows Service. The service will need a username/password from the user in order to get information from our server, so I'd like to set that during install. We also need to store that info in the Services config file so it has to be encrypted.
So I'd like the installer to call the same .dll the service uses when it encrypts the credentials. I set up custom actions created through the custom action wizard. I set it to "Call a public method in a managed assembly" and picked "Installed with the product" as the Location. I'm able to pick the dll and the target function and set everything up through the wizard. The path it resolves to in the installer log looks correct...
But I'm getting the error:
Unable to load managed custom action assembly
So not sure what to do in order to get this working?
The second part of the question is, what happens if the end user doesn't have .NET 4 installed? I'm going to set the installer to install it... but will there be problems or will we need to force a reboot partway through the install process? If so I might just temporarily store things unencrypted and have the service encrypt them when it first runs... which at this point is probably the easy way, but it doesn't feel like the "correct" way. ;)

Resources