winget-cli icon indicating copy to clipboard operation
winget-cli copied to clipboard

When configurations file due to not being elevated... we should retry with Sudo

Open KevinLaMS opened this issue 1 year ago • 2 comments

Description of the new feature / enhancement

I ran a config and errored:

You are responsible for understanding the configuration settings you are choosing to execute. Microsoft is not responsible for the configuration file you have authored or imported. This configuration may change settings in Windows, install software, change software settings (including security settings), and accept user agreements to third-party packages and services on your behalf.  By running this configuration file, you acknowledge that you understand and agree to these resources and settings. Any applications installed are licensed to you by their owners. Microsoft is not responsible for, nor does it grant any licenses to, third-party packages or services. Have you reviewed the configuration and would you like to proceed applying it to the system? [Y] Yes [N] No: y Apply :: DeveloperMode Configuration successfully applied. Apply :: WinGetPackage [vsPackage] Configuration successfully applied. Apply :: VSComponents Loading the module for the configuration unit failed because it requires administrator privileges to run. Some of the configuration was not applied successfully.

It would make a ton of sense to help the user fix it. How about

"Dude, loading the module for the configuration unit failed because it requires administrator privileges to run. Some of the configuration was not applied successfully." Would you like to try again using Sudo? [Y/N] :

Proposed technical implementation details

The user can then choose to use Sudo to try again as admin.

  1. this cannot happen in script as we cannot block
  2. we NEED the result of Sudo to be returned. If you run sudo Winget search foo, it will launch but the results are not returned as the sudo cmd is dismissed.

KevinLaMS avatar Sep 16 '24 22:09 KevinLaMS

There could be a --RetryWithSudo switch to handle this in automation.

stephengillie avatar Sep 17 '24 14:09 stephengillie

The default behavior when sudo is enabled is "In a new window". It can be changed to "inline" which will present the output in the current window.

You can pass the "--wait" argument which will pause until [Enter] is pressed if the "In a new window" option is required by Group Policy.

denelon avatar Sep 18 '24 21:09 denelon

We've added support for an elevation via the securityContext key.

Under the "directives:" for a resource, add "securityContext: elevated". WinGet will know that resource requires elevation, and it will prompt for a UAC (User Account Control) when the configuration is executed.

denelon avatar Feb 24 '25 16:02 denelon