Innosetup: Set admin privileges optionally

I maintain a desktop app where the Windows build is distributed as an InnoSetup installer package. For all features to work, the app needs elevated privileges, but for some of the users with more restrictive security policies, only normal user privileges are allowed. So the Xojo build is done with user privileges only.
I’d like to have an Innosetup checkbox that enables admin privileges on the freshly installed app on demand. Is that possible? And how?

My recollection of this is that the installer doesn’t have control over that. Yea, an installer can run in admin mode so it can be installed and do certain admin level things (like adding a firewall entry or setting up a service) but overriding whether the program runs as an admin could seriously compromise a systems security.

Could you explain what your app does that it needs admin privileges to function? Maybe there’s another option you haven’t considered.

Sure. First there is Kaju Updater included which needs to run in Admin mode if it should install a new version.
Then there’s a Windows service being a bit unstable, and often after usage (it’s connected to a color measurement instrument) it will stop. I need admin privileges to bring it back alive.

I have a checkbox for “Set Run as Admin flag” in Plugins Pro which sets a registry key. I have found InnoSetup really easy to Google questions for, look out for other awesome quirks with my installers :wink:

image

[Setup]
; Since we're setting Run as Admin flag, but idk this may be overkill
PrivilegesRequired=admin

[Tasks]
Name: "runadmin"; Description: "Set Run as Admin flag for Plugins Pro"; GroupDescription: "Permissions:"

[Registry]
; Set Run as Admin
Root: "HKLM"; Subkey: "SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers"; \
    ValueType: String; ValueName: "{app}\Plugins Pro.exe"; ValueData: "RUNASADMIN"; \
    Flags: uninsdeletekeyifempty uninsdeletevalue; MinVersion: 0,6.1; Tasks: "runadmin"
3 Likes

Thanks a lot, Tim! That was exactly what I was looking for.
Your Google must be a different one than mine. I cannot tell you how many hours I spent searching for different InnoSetup explanations …

1 Like

I am sorry, Tim, but it turned out this flag isn’t working for me. It might be because we are only supplying a 32bit version even on Win 64 bit systems. Do you have an idea if a different registry key would have to be set in this case? (Ugh, my limited Windows knowledge)

This is digging out of my old knowledge so it might need testing.

If you are running a 32bit installer and a 32bit app then this should be ok as

SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers

will be redirected to

SOFTWARE\WOW6432Node\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers

If you are running a 64bit installer and a 32bit app then the installer needs to make the registry change in

SOFTWARE\WOW6432Node\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers

as that is where the 32bit app will be looking for the elevation setting when running on a 64bit OS.

1 Like