make winget run as admin instead of asking for admin on each installer #3185
-
Description of the new feature / enhancementcould it be possible to make winget run as admin and then run the installers as admin or user depending on if they need to install to appdata or program files Proposed technical implementation detailswinget is run as admin > winget runs installer either as admin or user based on manifest > install done |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments 12 replies
-
@Sakooooo we're doing some work now with the "elevatesSelf" property in the manifest to enlighten ourselves when a package will trigger UAC prompt. We're working on some scenarios where we can logically call a single UAC request for a set of packages to be installed in that context. Some users will not have the ability to elevate, and we need to be able to reason about that particular scenario as well. Interestingly, there are also packages that will not install in admin and we've added "elevationProhibited". In those cases, running in admin will fail, and we need to reason about "de-elevation" to some "appropriate" user account. |
Beta Was this translation helpful? Give feedback.
-
What about a scenario where the organization locks down user ability to run anything from winget themselves and only wants admins to be able to run it, period. |
Beta Was this translation helpful? Give feedback.
-
After starting PowerShell and entering the Failed when searching source: winget When I run powershell as a user, everything is fine, only the applocker cuts it. |
Beta Was this translation helpful? Give feedback.
-
Same here, PowerShell as administrator and An unexpected error occurred while executing the command: As user everything works fine, except the annoying step to enter administrator login on every install... |
Beta Was this translation helpful? Give feedback.
-
Is there a solution to this now? Do all manifests have information "elevatesSelf" or "elevationProhibited" by now? It seems pretty easy then: get admin-rights with one UAC and after all relevent installs/updates are done drop back to user rights - that's all, isn't it? (vice-versa would mean that UAC does not pop-up in the beginning, which is no good usability.) |
Beta Was this translation helpful? Give feedback.
-
Yes, it is required for each installer, but it would be more conveniant if it was only once and at the beginning of install (so you can leave it unattended afterwards and not come back finding a UAC or an error after timeout) |
Beta Was this translation helpful? Give feedback.
-
For every packet winget determines whether to elevate or not. simply catch all manifests, sort by elevate /not elevate and elevate the thread/subprocess/... that handles the elevated ones. If an installer does elevate on its own, why is it a problem to do UAC before? |
Beta Was this translation helpful? Give feedback.
-
I've solved this by starting in a regular unelevated shell and running some winget commands there. Then for the packages that need admin I create an elevated Powershell process, this means one UAC prompt, and connect to it via named pipe IPC from the unelevated shell. Then I can send any winget packages, or really any command at all from the unelevated shell to the elevated shell and it will queue and execute them all with administrator permissions. This avoids any further UAC prompts and I can act as both a standard user and an administrator simultaneously. However this requires a bit of boilerplate PowerShell scripting and maybe isn't super beginner friendly. |
Beta Was this translation helpful? Give feedback.
For that you can run PowerShell/CMD as administrator and accept the UAC prompt once and run
winget upgrade --all
- this would fail for packages that don't allow installation in an elevated context but to be fair those packages are a very small minority