Skip to content

Warn when Chocolatey is used without an elevated shell #13

Description

@trmxvibs

Context

ChocoBackend sets requires_root = False because Windows has no sudo
and pkgwrap cannot elevate a running process. But Chocolatey genuinely
needs an elevated (Administrator) shell for install and remove. Today the
user only finds out when choco itself fails, with a message that doesn't
mention pkgwrap at all.

WindowsBackend (winget) doesn't have this problem — winget raises its own
UAC prompt when it needs elevation.

Proposal

Detect elevation on Windows and print a clear warning before running a
choco command that needs it:

import ctypes
ctypes.windll.shell32.IsUserAnAdmin()

The warning should say what to do ("run this from an Administrator
PowerShell or Command Prompt"), not just that something is wrong. This
should be a warning, not a hard failure — the user may have choco
configured differently.

Acceptance criteria

  • A helper that reports elevation status on Windows and is a safe
    no-op elsewhere (Linux/macOS/CI runners)
  • choco install/remove/upgrade warn when not elevated
  • Tests cover both the elevated and non-elevated paths with the check
    mocked
  • Nothing changes on non-Windows platforms

Pointers

  • src/pkgwrap/backends/choco_backend.py
  • src/pkgwrap/backends/brew_backend.py has a similar warning for the
    opposite problem (brew refuses to run as root) — follow that pattern

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions