Circumstances:
Hello everyone, I using Inno Setup 5.5.6(u) to create my setups.
It has to be version 5.x to support some older OS.
By default the UAC requests elevation and if clicked "No" it offers to run unelevated - I use the seccond solution from Martin Prikryl to get this to work.
The reason for why I not put that in his comments is that the topic seems a bit different to me and it looks more of a general problem with Inno Setup to me.
Problem:
When accounts without membership of administrator group run the code and use 'optional' UAC with credentials from any administrator account the following problem occurs: Inno Setup keeps the non administrative install mode (e.g. uninstall entry, desktop icon) for the administrator account you entered the credentials for only. The program itself will be installed under ProgramFiles fine due to IsAdminLoggedOn. Any other user (including your limited user account from where you perform the install) can not call the desktop icon or the uninstall.
What I have tried so far:
So, can anyone help me switching to administrative install mode from within [Code] manually? Please do not suggest the followng as I have tried this in vain already:
- Not work:
PrivilegesRequiredOverridesAllowed- I have to use version 5.x for compatibility reasons and back then this command can not be interpreted at all. - Not work:
PrivilegesRequired=adminorPrivilegesRequired=none- if I would use them I would not be able to catch elevation denied by user and offer unelevated install. - Not work: Command-line parameter
/ALLUSERStheoretically should do the trick but does not work for me too. Maybe version 5 does not support it too... - Not work:
Function IsAdminInstallModeis not recognized by setup either (when compiling error message tells me 'Unknown identifier [...]'). - Kind of dirty solution: Creating two additional subordinate installers, one with admin privileges required one without is explained here: https://copyprogramming.com/howto/inno-setup-access-unprivileged-account-folders-from-installer-that-requires-privileges. But out of other reasons I embedded a setup inside a setup already. I would rather not nest them any further.
- Theoretical it should be possible considering the way Inno Setup works and the fact once UAC was accepted
IsAdminLoggedOnreturns True (look here: https://stackoverflow.com/a/65990073/22271111 - Not work: Preprocessor solutions are no option too currently. I tried to set
PrivilegesRequired={#PrivilegesRequired}and added query for the ISPP to#define PrivilegesRequired "{code:VerifyAdmin}"depending on whetherIsAdminLoggedOnin code is true or not. But then it comes to me that this [Setup] setting is statically build in setup and changes at runtime won't get recognized (at least not those from code section). - Inno Setup guide itself and google results do not address that matter (including Stackoverflow), thats why I created a question here.
Expected solution:
If everything went well, Inno Setup should switch to administrative install mode if UAC was accepted at runtime (pseudo command: set {#SetupSetting("PrivilegesRequired")} := 'admin'). I would be happy if I can tell the compiler to do so with some [Code] section commands.
I know, Inno Setup 5.x is outdated by now and does not provide great security, but I want to repack some application and free games only - no going to create an antivirus suite.
Indeed, there seems to be no way to switch between administrative and non-administrative mode at runtime. But here is a workaround for the most relevant constants. It includes Martin Prikryl's solution but there is so much more that it does not seem to belong to the original discussion.
I tested my code on Windows XP,7,11 - it works fine on all of them:
Maybe someone will find this useful, especially since its designed to be backward-compatible down to Windows 2000.