microsoft / microsoft/winget-cli

Winget not found - problems with active directory accounts and using winget

Open
#4,804 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue-Bug
Dominant language
C++
Stars
26.4k
Forks
1.8k
Avg merge
1d 11h
Merged PRs (30d)
15

Description

Brief description of your issue

We like to use Winget to supply computers with complete software. Unfortunately, we are currently unable to install Winget in such a way that it is available to all users. This is a big problem for our admins (they are in a local admin group, but use domain accounts).
Whenever they start an administrative cmd, they get an error that Winget cannot be found. This is our current code to install Winget on the devices:

function Install-WinGet {
  param (
    [string]$folder,
    [switch]$Prerelease
  )

  $tempFolderName = 'WinGetInstall'
  $tempFolder = Join-Path -Path $folder -ChildPath $tempFolderName
  New-Item $tempFolder -ItemType Directory -ErrorAction SilentlyContinue | Out-Null

  $apiLatestUrl = if ($Prerelease) { 'https://api.github.com/repos/microsoft/winget-cli/releases?per_page=1' } else { 'https://api.github.com/repos/microsoft/winget-cli/releases/latest' }
  [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
  $WebClient = New-Object System.Net.WebClient

  function Get-LatestUrl {
    ((Invoke-WebRequest $apiLatestUrl -UseBasicParsing | ConvertFrom-Json).assets | Where-Object { $_.name -match '^Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle$' }).browser_download_url
  }

  function Get-LatestHash {
    $shaUrl = ((Invoke-WebRequest $apiLatestUrl -UseBasicParsing | ConvertFrom-Json).assets | Where-Object { $_.name -match '^Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.txt$' }).browser_download_url
    $shaFile = Join-Path -Path $tempFolder -ChildPath 'Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.txt'
    $WebClient.DownloadFile($shaUrl, $shaFile)
    Get-Content $shaFile
  }

  function Get-VersionFromUrl($url) {
    if ($url -match '/releases/download/v([\d\.]+)/') {
      return $matches[1]
    }
    throw "Unable to extract version from URL: $url"
  }

  function Get-LicenseFileUrl($version) {
    $licenseAsset = (Invoke-WebRequest $apiLatestUrl -UseBasicParsing | ConvertFrom-Json).assets | Where-Object { $_.name -match "${version}_License1.xml$" }
    if ($licenseAsset -ne $null) {
      return $licenseAsset.browser_download_url
    }
    throw "License file not found for version $version in the release assets."
  }

  $desktopAppInstaller = @{
    fileName = 'Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle'
    url      = $(Get-LatestUrl)
    hash     = $(Get-LatestHash)
  }
  $vcLibsUwp = @{
    fileName = 'Microsoft.VCLibs.x64.14.00.Desktop.appx'
    url      = 'https://aka.ms/Microsoft.VCLibs.x64.14.00.Desktop.appx'
    hash     = 'B56A9101F706F9D95F815F5B7FA6EFBAC972E86573D378B96A07CFF5540C5961'
  }
  $uiLibsUwp = @{
    fileName = 'Microsoft.UI.Xaml.2.8.x64.appx'
    url      = 'https://github.com/microsoft/microsoft-ui-xaml/releases/download/v2.8.6/Microsoft.UI.Xaml.2.8.x64.appx'
    hash     = '249D2AFB41CC009494841372BD6DD2DF46F87386D535DDF8D9F32C97226D2E46'
  }

  $dependencies = @($desktopAppInstaller, $vcLibsUwp, $uiLibsUwp)
  Write-Host '--> Checking dependencies'
  foreach ($dependency in $dependencies) {
    $dependency.file = Join-Path -Path $tempFolder -ChildPath $dependency.fileName
    if (-Not ((Test-Path -Path $dependency.file -PathType Leaf) -And $dependency.hash -eq $(Get-FileHash $dependency.file).Hash)) {
      Write-Host @"
    - Downloading:
      $($dependency.url)
"@
      try {
        $WebClient.DownloadFile($dependency.url, $dependency.file)
      }
      catch {
        # Pass the exception as an inner exception
        throw "Error downloading $($dependency.url)."
      }
      if (-not ($dependency.hash -eq $(Get-FileHash $dependency.file).Hash)) {
        throw "Dependency hash does not match the downloaded file"
      }
    }
  }

  # Extract version from the WinGet URL
  $wingetVersion = Get-VersionFromUrl -url $desktopAppInstaller.url

  # Get the license file URL
  $licenseFileUrl = Get-LicenseFileUrl -version $wingetVersion
  $licenseFilePath = Join-Path -Path $tempFolder -ChildPath 'License1.xml'

  # Download the license file
  Write-Host "--> Downloading license file: $licenseFileUrl"
  try {
    $WebClient.DownloadFile($licenseFileUrl, $licenseFilePath)
  }
  catch {
    throw "Error downloading license file from $licenseFileUrl."
  }

  # Install dependencies
  Write-Host '--> Installing dependencies'
  Add-AppxPackage -Path $($vcLibsUwp.file)
  Add-AppxPackage -Path $($uiLibsUwp.file)

  # Install WinGet
  Write-Host '--> Installing WinGet'
  Add-AppxPackage -Path $($desktopAppInstaller.file)

  # Configure WinGet with the correct license file
  Write-Host '--> Configuring WinGet with the license file'
  Add-AppxProvisionedPackage -Online -PackagePath $($desktopAppInstaller.file) -LicensePath $licenseFilePath
}

If you have any better ideas or if it is a feature that is missing, please mark it - we are grateful for everything!
And thanks for all the work on Winget!

Translated with DeepL.com (free version)

Steps to reproduce

install winget and use an different user from that system

Expected behavior

install winget and use it with every user (even ones that comes later to that system as an domain user;))

Actual behavior

winget couldnt be found

Environment
Windows-Paket-Manager v1.8.1911
Copyright (c) Microsoft Corporation. Alle Rechte vorbehalten.

Windows: Windows.Desktop v10.0.22631.4037
Systemarchitektur: X64
Paket: Microsoft.DesktopAppInstaller v1.23.1911.0

WinGet-Verzeichnisse
-----------------------------------------------------------------------------------------------------------------------
Protokolle                                   %LOCALAPPDATA%\Packages\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\Local…
Benutzereinstellungen                        %LOCALAPPDATA%\Packages\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\Local…
Verzeichnis für portierbare Links (Benutzer) %LOCALAPPDATA%\Microsoft\WinGet\Links
Portables Linkverzeichnis (Computer)         C:\Program Files\WinGet\Links
Portierbarer Paketstamm (Benutzer)           %LOCALAPPDATA%\Microsoft\WinGet\Packages
Portierbarer Paketstamm                      C:\Program Files\WinGet\Packages
Portierbares Paketstamm (x86)                C:\Program Files (x86)\WinGet\Packages
Installationsprogrammdownloads               %USERPROFILE%\Downloads

Links
-----------------------------------------------------------------------------------------
Datenschutzerklärung              https://aka.ms/winget-privacy
Lizenzvereinbarung                https://aka.ms/winget-license
Hinweise von Drittanbietern       https://aka.ms/winget-3rdPartyNotice
Startseite                        https://aka.ms/winget
Windows Store-Nutzungsbedingungen https://www.microsoft.com/en-us/storedocs/terms-of-sale

Administratoreinstellung                  Status
-----------------------------------------------------
LocalManifestFiles                        Deaktiviert
BypassCertificatePinningForMicrosoftStore Deaktiviert
InstallerHashOverride                     Deaktiviert
LocalArchiveMalwareScanOverride           Deaktiviert
ProxyCommandLineOptions                   Deaktiviert
DefaultProxy                              Deaktiviert

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided Install-WinGet PowerShell function, especially its Add-AppxPackage and Add-AppxProvisionedPackage entry points, and reproduce the installation with a separate domain account. Inspect the reported WinGet directories and command lookup behavior for administrators and users added later; done means winget is available to all intended users.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, powershell
Domain
cli, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.