PDA

View Full Version : How can we change Execution Level runtime



testuser
08-31-2020, 04:11 AM
Hello,

I am not sure whether it is possible or not, Can we change UAC execution level dynamically?

Requirement:
1. We want to show user 2 options : A. Machine Wide B. Per-User
2. If user selects Machine Wide option then we want to ask user for permission(UAC) and set installation path in Program Files.(like highestAvailable)
3. If user selects Per-User option the we don't want to ask user permission and set installation in LocalAppData.(like asInvoker)

I guess its not possible but can we do installation in Program Files without UAC permission.


Thanks in Advance!

linder
08-31-2020, 05:39 AM
Hello,

the manifest in an executable determines the execution level. So Windows does not allow to change the execution level "dynamically".

What you have to do in this case is to use an "asInvoker" wrapper. This runs by default "per-user". Ask the "per-user" / "per-machine" question and if it is a per-machine install, start the main installation elevated from this wrapper.

BTW, never use "highestAvailable". Use asInvoker or requireAdministrator.

Windows does not allow to write to protected resources (e.g. Program Files, Windows, HKEY_LOCAL_MACHINE) from a non-elevated running application.

Friedrich

testuser
08-31-2020, 06:09 AM
Thanks for the immediate reply!

What do you mean by wrapper?

Can you please elaborate "start the main installation elevated from this wrapper." ?

linder
08-31-2020, 06:22 AM
Hello,

You have several different options. I have uploaded a quick-and-dirty demo project:

https://www.setupbuilder.com/projects/UserOption.zip

By default, it runs (on UAC-aware) operating systems "asInvoker" (per-user). You can select "per-machine" and it re-starts itself as "requireAdministrator" (per-machine).-

Does this help?

Friedrich

testuser
09-02-2020, 01:49 AM
Yes, it helps us to achieve our requirement.

Thanks you very much Friedrich for the demo application.