Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
unclesam87 opened this issue Sep 11, 2024 · 6 comments
Labels
Issue-Bug It either shouldn't be doing this or needs an investigation.

Comments

@unclesam87
Copy link

unclesam87 commented Sep 11, 2024

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
@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs-Triage Issue need to be triaged label Sep 11, 2024
Copy link

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

@Trenly
Copy link
Contributor

Trenly commented Sep 11, 2024

@unclesam87 - Have you tried using Add-AppxProvisionedPackage instead? IIRC, Add-AppxPackage only installs it for the current user, but Add-AppxProvisionedPackage will add it for the current user and all new users.

Edit: Whoops, didn’t read far enough; Now I see it at the bottom

@microsoft-github-policy-service microsoft-github-policy-service bot removed the Needs-Triage Issue need to be triaged label Sep 11, 2024
@stephengillie
Copy link

I'm not sure, but could a Group Policy setting be causing an issue?

@denelon
Copy link
Contributor

denelon commented Sep 11, 2024

We built the Repair-WinGetPackageManager cmdlet in the Microsoft.WinGet.Client PowerShell module to help with bootstrapping WinGet.

Repair-WinGetPackageManager -Latest -force should ensure the latest stable version of WinGet (known to the version of the module) is installed and functioning.

@denelon denelon added the Issue-Bug It either shouldn't be doing this or needs an investigation. label Sep 11, 2024
@unclesam87
Copy link
Author

unclesam87 commented Sep 12, 2024

thank u! this function has to be run for every user who tries to run winget right? or can we automate this a bit?

@denelon
Copy link
Contributor

denelon commented Sep 13, 2024

You could leverage the Microsoft.WinGet.Client PowerShell module to automate the process of ensuring the latest stable version of WinGet is installed using the Repair-WinGetPackageManager cmdlet:
Repair-WinGetPackageManager -Latest -Force

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Bug It either shouldn't be doing this or needs an investigation.
Projects
None yet
Development

No branches or pull requests

4 participants