microsoft / winget-cli

WinGet is the Windows Package Manager. This project includes a CLI (Command Line Interface), PowerShell modules, and a COM (Component Object Model) API (Application Programming Interface).
https://learn.microsoft.com/windows/package-manager/
MIT License
23.08k stars 1.44k forks source link

Broken winget after installing Windows 11 and all its updates #3832

Closed lackovic closed 11 months ago

lackovic commented 11 months ago

Brief description of your issue

I have installed Windows 11 on a laptop and completed all the system updates. When I tried to run some winget commands like winget search or winget install I got an empty output, though the text color of the prompt would turn blue.

(1) I tried to update winget from the Microsoft Store but there was no Update button under App Installer.

(2) When I tried to uninstall winget and install it back with the command:

Get-AppxPackage | ? {$_.Name -match 'AppInstaller'} | Remove-AppxPackage; Add-AppxPackagehttps://aka.ms/getwinget

I got the following error:

Remove-AppxPackage : Deployment failed with HRESULT: 0x80073CFA, Removal failed. Please contact your software vendor. (Exception fro
m HRESULT: 0x80073CFA)
error 0x80070032: AppX Deployment Remove operation on package Microsoft.DesktopAppInstaller_1.21.2771.0_x64__8wekyb3d8bbwe from: C:\
Program Files\WindowsApps\Microsoft.DesktopAppInstaller_1.21.2771.0_x64__8wekyb3d8bbwe failed. This app is part of Windows and canno
t be uninstalled on a per-user basis. An administrator can attempt to remove the app from the computer using Turn Windows Features o
n or off. However, it may not be possible to uninstall the app.
NOTE: For additional information, look for [ActivityId] 88ce017c-0b27-000b-0340-cf88270bda01 in the Event Log or use the command lin
e Get-AppPackageLog -ActivityID 88ce017c-0b27-000b-0340-cf88270bda01
At line:1 char:55
+ ... kage | ? {$_.Name -match 'AppInstaller'} | Remove-AppxPackage; Add-Ap ...
+                                                ~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (Microsoft.Deskt...__8wekyb3d8bbwe:String) [Remove-AppxPackage], IOException
    + FullyQualifiedErrorId : DeploymentError,Microsoft.Windows.Appx.PackageManager.Commands.RemoveAppxPackageCommand

Add-AppxPackagehttps://aka.ms/getwinget : The term 'Add-AppxPackagehttps://aka.ms/getwinget' is not recognized as the name of a cmdl
et, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is c
orrect and try again.
At line:1 char:75
+ ... aller'} | Remove-AppxPackage; Add-AppxPackagehttps://aka.ms/getwinget
+                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                                                              + CategoryInfo          : ObjectNotFound: (Add-AppxPackagehttps://aka.ms/getwinget:String) [], CommandNotFoundException              + FullyQualifiedErrorId : CommandNotFoundException  

(3) When I ran:

winget source update

I got:

Updating all sources...
Updating source: msstore...
Done
Updating source: winget...
  ██████████████████████████████  100%
Done

and then winget started working.

Steps to reproduce

Install Windows 11 on a computer and install all the updates.

Expected behavior

winget is working.

Actual behavior

winget is not working.

Environment

Windows Package Manager v1.6.2771
Copyright (c) Microsoft Corporation. All rights reserved.

Windows: Windows.Desktop v10.0.22621.2506
System Architecture: X64
Package: Microsoft.DesktopAppInstaller v1.21.2771.0
stephengillie commented 11 months ago

Hi @lackovic,

Could you try ~uninstalling and~ reinstalling? The package manager can be found at https://aka.ms/GetWinGet if not through the Windows Store.

lackovic commented 11 months ago

Could you try uninstalling and reinstalling?

Why? Everything is working after the 3rd solution I mentioned.

denelon commented 11 months ago

@lackovic

A fresh install of Windows 11 comes with an earlier version of WinGet. The Microsoft Store will "eventually" update this version to the latest, and once the latest version is present, it should function correctly. Sometimes this happens 15 minutes or so after the install, and other times it may take a bit longer depending on what else needs to be updated via the Microsoft Store on the system.

Is there any chance you have logs from those first couple of commands you tried when you didn't get any output?

I suspect an upgrade may have been running during or immediately after those, and once the latest version was present, it started working.

stephengillie commented 11 months ago

Why? Everything is working after the 3rd solution I mentioned.

Sorry for not fully reading the Issue.

lackovic commented 11 months ago

A fresh install of Windows 11 comes with an earlier version of WinGet. The Microsoft Store will "eventually" update this version to the latest, and once the latest version is present, it should function correctly. Sometimes this happens 15 minutes or so after the install, and other times it may take a bit longer depending on what else needs to be updated via the Microsoft Store on the system.

Makes sense. That was my assumption as well, that's why when that happened I opened the App Installer in Microsoft Store: I was expecting to see the Update button but when I didn't see it I assumed winget was already up to date and that my fresh installation of Windows 11 was broken.

Is there any chance you have logs from those first couple of commands you tried when you didn't get any output?

Sure, here is one of them (which confirms your hypothesis):

2023-10-30 13:01:07.960 [CORE] WinGet, version [1.2.10691], activity [{5B248D77-5D50-486E-A216-07E21F24BDD2}]
2023-10-30 13:01:07.961 [CORE] OS: Windows.Desktop v10.0.22621.2428
2023-10-30 13:01:07.961 [CORE] Command line Args: "C:\Users\marco\AppData\Local\Microsoft\WindowsApps\winget.exe" search telegram
2023-10-30 13:01:07.961 [CORE] Package: Microsoft.DesktopAppInstaller v1.17.10691.0
2023-10-30 13:01:07.961 [CORE] IsCOMCall:0; Caller: winget-cli
2023-10-30 13:01:07.965 [CLI ] WinGet invoked with arguments: 'search' 'telegram'
2023-10-30 13:01:07.965 [CLI ] Found subcommand: search
2023-10-30 13:01:07.965 [CLI ] Leaf command to execute: root:search
2023-10-30 13:01:07.965 [CLI ] Executing command: search
2023-10-30 13:01:07.973 [REPO] GetCurrentSourceRefs: Source named 'microsoft.builtin.desktop.frameworks' from origin Default is hidden and is dropped.
2023-10-30 13:01:07.973 [REPO] Default source requested, multiple sources available, adding all to source references.
2023-10-30 13:01:07.973 [REPO] Adding to source references msstore
2023-10-30 13:01:07.973 [REPO] Adding to source references winget
2023-10-30 13:01:07.974 [REPO] Source past auto update time [5 mins]; it has been at least 28311061 mins
denelon commented 11 months ago

Thanks for sharing the log output. We are doing some work in future releases of Windows to reduce the time period for the registration activity, but for now sadly, this is the expected behavior.

HeinziAT commented 10 months ago

We are doing some work in future releases of Windows to reduce the time period for the registration activity

In the mean time, is there some workaround we can use? Maybe some CLI command that updates winget?

Having to wait an indeterminate amount of time with no indication of progress is a bit frustrating when setting up a new PC...

mdanish-kh commented 10 months ago

@HeinziAT

You can use the following PowerShell command

Add-AppxPackage -RegisterByFamilyName -MainPackage Microsoft.DesktopAppInstaller_8wekyb3d8bbwe

Reference: https://learn.microsoft.com/en-us/windows/package-manager/winget/#install-winget

You can also directly install winget with its dependencies through the sandbox script.

HeinziAT commented 10 months ago

@mdanish-kh

Unfortunately, that PowerShell command doesn't work: A progress bar shortly pops up, the command completes without error, but winget is still "broken".

The sandbox script works, though. Thanks!

HeinziAT commented 10 months ago

After some more testing, on a newly installed Windows 11 23H2, the following Powershell commands suffice to get winget up and running:

Invoke-WebRequest -Uri https://aka.ms/getwinget -OutFile winget.msixbundle
Add-AppxPackage winget.msixbundle
del winget.msixbundle
dschu012 commented 9 months ago

After some more testing, on a newly installed Windows 11 23H2, the following Powershell commands suffice to get winget up and running:

Invoke-WebRequest -Uri https://aka.ms/getwinget -OutFile winget.msixbundle
Add-AppxPackage winget.msixbundle
del winget.msixbundle

I get

Add-AppxPackage : Deployment failed with HRESULT: 0x80073D02, The package could not be installed because resources it   modifies are currently in use.
error 0x80073D02: Unable to install because the following apps need to be closed
Microsoft.DesktopAppInstaller_1.17.10691.0_x64__8wekyb3d8bbwe.
NOTE: For additional information, look for [ActivityId] 4685bc32-380f-0002-c01a-87460f38da01 in the Event Log or use
the command line Get-AppPackageLog -ActivityID 4685bc32-380f-0002-c01a-87460f38da01
At line:1 char:1
+ Add-AppxPackage winget.msixbundle
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (C:\Windows\system32\winget.msixbundle:String) [Add-AppxPackage], Exceptio
   n
    + FullyQualifiedErrorId : DeploymentError,Microsoft.Windows.Appx.PackageManager.Commands.AddAppxPackageCommand

when doing that on a fresh Windows 11 23H2 install. winget source update nor any of the other solutions here seemed to work for me. All winget commands result in empty output and the prompt turning blue like the person who reported the issue.

Edit: Someone below mentioned adding -ForceApplicationShutdown to the Add-AppxPackage, that fixed it for me.

TheMadTexan42 commented 9 months ago

Likewise here just a minute ago. None of the potential fixes work on a brand new and freshly updated Win 11 install. Same "prompt turns blue" behavior and same error with the Powershell update process. Winget mostly seems to be hung up trying to interact with the winget source. The source update command worked fine for the store, but hung on the winget source.

snsgnq commented 9 months ago

After some more testing, on a newly installed Windows 11 23H2, the following Powershell commands suffice to get winget up and running:

Invoke-WebRequest -Uri https://aka.ms/getwinget -OutFile winget.msixbundle
Add-AppxPackage winget.msixbundle
del winget.msixbundle

I was able to fix it with these commands. Thank you! My case was also a fresh install of Win11 23H2 where winget didn't work and got a blue line of text.

wtfcxt commented 9 months ago

Likewise here just a minute ago. None of the potential fixes work on a brand new and freshly updated Win 11 install. Same "prompt turns blue" behavior and same error with the Powershell update process. Winget mostly seems to be hung up trying to interact with the winget source. The source update command worked fine for the store, but hung on the winget source.

Running this worked for me:

Invoke-WebRequest -Uri https://aka.ms/getwinget -OutFile winget.msixbundle
Add-AppPackage -ForceApplicationShutdown .\winget.msixbundle
del .\winget.msixbundle

The thing I changed, is adding the -ForceApplicationShutdown argument. For me, it fixed the issue @dschu012 mentioned and winget works fine on my system now.

ElectricWiz commented 9 months ago

Likewise here just a minute ago. None of the potential fixes work on a brand new and freshly updated Win 11 install. Same "prompt turns blue" behavior and same error with the Powershell update process. Winget mostly seems to be hung up trying to interact with the winget source. The source update command worked fine for the store, but hung on the winget source.

Running this worked for me:

Invoke-WebRequest -Uri https://aka.ms/getwinget -OutFile winget.msixbundle
Add-AppPackage -ForceApplicationShutdown .\winget.msixbundle
del .\winget.msixbundle

The thing I changed, is adding the -ForceApplicationShutdown argument. For me, it fixed the issue @dschu012 mentioned and winget works fine on my system now.

This also worked for me! thank you very much.

makedir commented 8 months ago

Same issue on fresh install of Windows 11 23h2 in Virtual Box. Winget doesnt work and gets empty feedback.

Eta-Beta commented 7 months ago

Good morning, I also confirm that it is not possible to update winget in any way or install the "Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" package in Windows 11 23H2. I hope they solve the problems because I created batch files to install software faster... I think I'll switch to Chocolatey.

jasonswearingen commented 7 months ago

I had this problem yesterday (winget not working due to wrong CDN), here is my description and solution: https://github.com/ChrisTitusTech/winutil/issues/1082#issuecomment-1955819034

the TLDR is to install winget install -s msstore --id 9NBLGGH4NNS1 which updates winget to a version with the right cdn.

miguno commented 7 months ago

I additionally needed to change to a directory other than C:\Windows\system32 (the default directory when starting Powershell in admin mode). Perhaps because the first command lacked write permissions for the downloaded file, even though the shell was run in admin mode. Unclear to me, but the steps below worked.

This worked:

# First, launch Powershell in administrator mode.

cd $HOME
Invoke-WebRequest -Uri https://aka.ms/getwinget -OutFile winget.msixbundle
Add-AppPackage -ForceApplicationShutdown .\winget.msixbundle
del .\winget.msixbundle
bennywave commented 7 months ago

This issue is still present in the Windows Version 23H2. I have fixed this issue on freshly installed systems by using the winget-install script from PSGallery:

Powershell as Administrator:

Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted
Install-Script -Name winget-install -Force
winget-install.ps1 -Force

This can be used if you don't want to touch anything besides powershell for fixing the issue

reinux commented 5 months ago

So this just happens on any clean install of Win11 now. Would a fix for this be part of a Windows update or?

jackhen commented 4 months ago

This issue is still present in the Windows Version 23H2. I have fixed this issue on freshly installed systems by using the winget-install script from PSGallery:

Powershell as Administrator:

Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted
Install-Script -Name winget-install -Force
winget-install.ps1 -Force

This can be used if you don't want to touch anything besides powershell for fixing the issue

I just tried this script to get winget to work on my Win 11 pc. It did not work and gave me these errors. What does this mean please? PS C:\Windows\system32> Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force

Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted
Install-Script -Name winget-install -Force winget-install.ps1 -Force

Name Version Source Summary


nuget 2.8.5.208 https://onege... NuGet provider for the OneGet meta-package manager

Then this error happened....(red color)

winget-install.ps1 : File C:\Program Files\WindowsPowerShell\Scripts\winget-install.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170. At line:4 char:1

bennywave commented 4 months ago

I just tried this script to get winget to work on my Win 11 pc. It did not work and gave me these errors. What does this mean please? PS C:\Windows\system32> Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force

Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted Install-Script -Name winget-install -Force winget-install.ps1 -Force

Name Version Source Summary

nuget 2.8.5.208 https://onege... NuGet provider for the OneGet meta-package manager

Then this error happened....(red color)

winget-install.ps1 : File C:\Program Files\WindowsPowerShell\Scripts\winget-install.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170. At line:4 char:1

  • winget-install.ps1 -Force_

You need to set the execution policy to unresticted for the script

For example:

powershell as admin powershell.exe -noprofile -executionpolicy bypass -file .\script.ps1

jackhen commented 4 months ago

Thank you for the response. Could you tell me how I go about setting the security policy before I try the script again? I'm not experienced in this sort of thing.

jackhen commented 4 months ago

I think I got it to work now. Winget installed successful as per powershell. Thank you.

Colonel-Hacker commented 4 months ago

The script method fixed it for me as well. I think part of my issue was forgetting to set the execution policy ( I am pretty sure I have a GPO that configures that, so I didn't even bother checking until I saw it mentioned in this thread)

JakeMalis commented 3 months ago

I think this happened to me is because I set my region to Global when installing Windows 11. I did try to use Winget after setting my region back to the US.

jason-lee-webdev commented 3 months ago

After some more testing, on a newly installed Windows 11 23H2, the following Powershell commands suffice to get winget up and running:

Invoke-WebRequest -Uri https://aka.ms/getwinget -OutFile winget.msixbundle
Add-AppxPackage winget.msixbundle
del winget.msixbundle

I had the same problem, but the solution above solved it. thank you

Nexxsys commented 3 months ago

No solutions noted above worked. winget is still unrecognized cmdlet. PowerShell 5 or 7 same results.

Nexxsys commented 3 months ago

Tried all the solutions above with the same results, winget not a recognized cmdlet. I had it but a recent windows update removed it??

PS C:\Users\nexxsys> winget-install
winget-install 4.1.2
To check for updates, run winget-install -CheckForUpdate
To delay script exit, run winget-install -Wait

#################
# Prerequisites #
#################

Downloading VCLibs...
Downloading UI.Xaml...

##########
# winget #
##########

Downloading winget license...
Downloading winget...
Installing winget and its dependencies...

############
# Complete #
############

winget installed successfully.
Checking if winget is installed and working...

###############
# Registering #
###############

winget command registered successfully.

PS C:\Users\nexxsys> winget
winget : The term 'winget' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify 
that the path is correct and try again.
At line:1 char:1
+ winget
+ ~~~~~~
    + CategoryInfo          : ObjectNotFound: (winget:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

PS C:\Users\nexxsys> 
WebDesignerlol commented 1 week ago

This issue is still present in the Windows Version 23H2. I have fixed this issue on freshly installed systems by using the winget-install script from PSGallery: Powershell as Administrator:

Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force
Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted
Install-Script -Name winget-install -Force
winget-install.ps1 -Force

This can be used if you don't want to touch anything besides powershell for fixing the issue

I just tried this script to get winget to work on my Win 11 pc. It did not work and gave me these errors. What does this mean please? PS C:\Windows\system32> Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force

Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted Install-Script -Name winget-install -Force winget-install.ps1 -Force

Name Version Source Summary

nuget 2.8.5.208 https://onege... NuGet provider for the OneGet meta-package manager

Then this error happened....(red color)

winget-install.ps1 : File C:\Program Files\WindowsPowerShell\Scripts\winget-install.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170. At line:4 char:1

  • winget-install.ps1 -Force_

this worked for me. crazy how many people it affects and microsoft has no easy fix available. should be standard and part of updates or doable via Microsoft store install