Search code examples
installationregistryinno-setupadministrator

Write HKLM when installed as Administrator, but HKCU otherwise, in Inno Setup


I've created my Inno Setup installer and it is working great. I just have one issue I'd like to solve. Not all of my users have Administrator rights, so my app has been set up to allow non admins to install. The problem is, I have set up a file association for my application and consequently need to set the correct registry keys for this.

As my users aren't all Administrators, I can't just use HKEY_LOCAL_MACHINE (HKLM). At the moment, I'm defaulting to HKEY_CURRENT_USER (HKCU).

Is there an elegant way to conditionally set HKLM if the user is an Administrator (selected the "install for all users" option) and HKCU if the users selects install to their own profile?


Solution

  • Seems this will do the trick:

    HKA (equals HKLM in administrative install mode, HKCU otherwise)

    Testing it now.