Devolutions/UniGetUI · error · UnauthorizedAccessException

This package cannot be installed from an elevated context.Pl

Error message

This package cannot be installed from an elevated context.Please check the installation options for this package and try again

What it means

WinGet ApplyElevationRequirements throws UnauthorizedAccessException when a package is ElevationProhibited AND the per-operation options explicitly request RunAsAdministrator=true. Distinct from error 98: here the process is not necessarily elevated, but the user/automation set the 'run as administrator' option on a package that forbids it. The message asks to check the installation options.

Source

Thrown at src/UniGetUI.PackageEngine.Managers.WinGet/Helpers/WinGetPkgOperationHelper.cs:217

                );
                package.OverridenOptions.RunAsAdministrator = true;
            }
            else if (
                installOptions?.ElevationRequirement is ElevationRequirement.ElevationProhibited
            )
            {
                if (CoreTools.IsAdministrator())
                    throw new UnauthorizedAccessException(
                        CoreTools.Translate(
                            "This package cannot be installed from an elevated context."
                        )
                            + CoreTools.Translate(
                                "Please run UniGetUI as a regular user and try again."
                            )
                    );

                if (options.RunAsAdministrator)
                    throw new UnauthorizedAccessException(
                        CoreTools.Translate(
                            "This package cannot be installed from an elevated context."
                        )
                            + CoreTools.Translate(
                                "Please check the installation options for this package and try again"
                            )
                    );

                package.OverridenOptions.RunAsAdministrator = false;
            }
            else if (
                installOptions?.Scope is PackageInstallerScope.System /* or PackageInstallerScope.Unknown*/
            )
            {
                Logger.Info(
                    $"WinGet package {package.Id} is installed on a system-wide scope, forcing administrator rights..."
                );
                package.OverridenOptions.RunAsAdministrator = true;

View on GitHub (pinned to 9b1d7d0eab)

Solutions

  1. Clear the 'Run as administrator' option for this package (package install options dialog) and retry.
  2. Disable the global 'always elevate' setting when installing per-user/Store apps.
  3. In automation, set options.RunAsAdministrator=false for packages with ElevationProhibited.

Example fix

// before
options.RunAsAdministrator = true; // throws for ElevationProhibited pkg
// after
var inst = NativePackageHandler.GetInstallationOptions(pkg, options, op);
options.RunAsAdministrator = inst?.ElevationRequirement is ElevationRequirement.ElevationProhibited
    ? false : options.RunAsAdministrator;
Defensive patterns

Strategy: validation

Validate before calling

// Caller guard: never request admin for a prohibited package.
var inst = NativePackageHandler.GetInstallationOptions(pkg, options, op);
if (inst?.ElevationRequirement is ElevationRequirement.ElevationProhibited)
    options.RunAsAdministrator = false;

Type guard

static bool ProhibitsElevation(InstallationOptions? o) =>
    o?.ElevationRequirement is ElevationRequirement.ElevationProhibited;

Prevention

When it happens

Trigger: Installing a WinGet package marked ElevationProhibited while options.RunAsAdministrator is set true (toggled in the package's install options dialog or passed by automation).

Common situations: User toggled 'Run as administrator' globally or per-package for an app that disallows elevation; automation forces admin for every package.

Related errors


AI-assisted analysis of Devolutions/UniGetUI@9b1d7d0eab (2026-08-13). Data as JSON: /api/errors/5f99a64a6fc707bb. Report an issue: GitHub.