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
22.95k stars 1.43k forks source link

`winget list --scope machine` fails with an error #3898

Open piotrminkina opened 10 months ago

piotrminkina commented 10 months ago

Brief description of your issue

Listing packages with --scope machine fails with error.

Steps to reproduce

For tests You can install Git.Git with --scope machine, e.g. winget install --id Git.Git --scope machine, then try to list installed packages:

> winget list --exact Git.Git
Name Id      Version  Source
-----------------------------
Git  Git.Git 2.42.0.2 winget
> winget list --exact Git.Git --scope user
No installed package found matching input criteria.
> winget list --exact Git.Git --scope machine
Failed to open the predefined source; please report to winget maintainers.
An unexpected error occurred while executing the command:
0x80070005 : unknown error
> winget list --scope user
Name                           Id                                Version           Source
-----------------------------------------------------------------------------------------
[...]
> winget list --scope machine
Failed to open the predefined source; please report to winget maintainers.
An unexpected error occurred while executing the command:
0x80070005 : unknown error

Expected behavior

Expect no errors.

Actual behavior

Failed to open the predefined source; please report to winget maintainers.
An unexpected error occurred while executing the command:
0x80070005 : unknown error

Environment

> winget --info
Windows Package Manager v1.6.3133
Copyright (c) Microsoft Corporation. All rights reserved.

Windows: Windows.Desktop v10.0.22631.2428
System Architecture: X64
Package: Microsoft.DesktopAppInstaller v1.21.3133.0

Winget Directories
-------------------------------------------------------------------------------------------------------------------------------
Logs                               %LOCALAPPDATA%\Packages\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\LocalState\DiagOutputDir
User Settings                      %LOCALAPPDATA%\Packages\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\LocalState\settings.json
Portable Links Directory (User)    %LOCALAPPDATA%\Microsoft\WinGet\Links
Portable Links Directory (Machine) C:\Program Files\WinGet\Links
Portable Package Root (User)       %LOCALAPPDATA%\Microsoft\WinGet\Packages
Portable Package Root              C:\Program Files\WinGet\Packages
Portable Package Root (x86)        C:\Program Files (x86)\WinGet\Packages
Installer Downloads                %USERPROFILE%\Downloads

Links
---------------------------------------------------------------------------
Privacy Statement   https://aka.ms/winget-privacy
License Agreement   https://aka.ms/winget-license
Third Party Notices https://aka.ms/winget-3rdPartyNotice
Homepage            https://aka.ms/winget
Windows Store Terms https://www.microsoft.com/en-us/storedocs/terms-of-sale

Admin Setting                             State
--------------------------------------------------
LocalManifestFiles                        Disabled
BypassCertificatePinningForMicrosoftStore Disabled
InstallerHashOverride                     Disabled
LocalArchiveMalwareScanOverride           Disabled
denelon commented 10 months ago

@piotrminkina

Can you try winget source reset --force and let me know if that resolves the error?

piotrminkina commented 10 months ago

Hello @denelon, no improvement.

> sudo winget source reset --force
Resetting all sources...Done
> winget list --scope machine
The `msstore` source requires that you view the following agreements before using.
Terms of Transaction: https://aka.ms/microsoft-store-terms-of-transaction
The source requires the current machine's 2-letter geographic region to be sent to the backend service to function properly (ex. "US").

Do you agree to all the source agreements terms?
[Y] Yes  [N] No: y
Failed to open the predefined source; please report to winget maintainers.
An unexpected error occurred while executing the command:
0x80070005 : unknown error

Don't let the sudo deceive you ;) I run the command in Windows Terminal, in Powershell (as in the notification). The sudo command provides me with the gerardog.gsudo package.

I was stumped when I wrote the above paragraph and decided to check this command with Administrator privileges.

> sudo winget list --scope machine
Name                                     Id                                                   Version           Available      Source
-------------------------------------------------------------------------------------------------------------------------------------
Adobe Acrobat Reader                     AdobeAcrobatReaderCoreApp_pc75e8sa7ep4e              23.0.0.0
[...]

It seems that the problem occurs on the rights of a regular user.

Regards Piotr Minkina

Trenly commented 10 months ago

@piotrminkina - do you have separate accounts that you're using for the Administrator privileges and the User privileges? I've seen in some cases that winget doesn't perform as expected across multiple user accounts

piotrminkina commented 10 months ago

@Trenly I wrote the Issue on the default account, created during the installation of the system, which is in the Administrators group. I also have an additional account created (with a User Profile created), which is in the Users group, but I don't use that account yet.

denelon commented 10 months ago

@piotrminkina can you try uninstalling the source and then running a search in the user context?

winget uninstall Microsoft.Winget.Source_8wekyb3d8bbwe should remove the source.

piotrminkina commented 9 months ago

@denelon Still no improvement.

> sudo winget uninstall Microsoft.Winget.Source_8wekyb3d8bbwe
Found Windows Package Manager Source (winget) [Microsoft.Winget.Source_8wekyb3d8bbwe]
Starting package uninstall...
  ██████████████████████████████  100%
Successfully uninstalled
> winget list --scope machine
Failed to open the predefined source; please report to winget maintainers.
An unexpected error occurred while executing the command:
0x80070005 : unknown error
> winget uninstall --scope user Microsoft.Winget.Source_8wekyb3d8bbwe
Found Windows Package Manager Source (winget) [Microsoft.Winget.Source_8wekyb3d8bbwe]
Starting package uninstall...
  ██████████████████████████████  100%
Successfully uninstalled
> winget list --scope machine
Failed to open the predefined source; please report to winget maintainers.
An unexpected error occurred while executing the command:
0x80070005 : unknown error
> winget --info
Windows Package Manager v1.6.3133
Copyright (c) Microsoft Corporation. All rights reserved.

Windows: Windows.Desktop v10.0.22631.2715
System Architecture: X64
Package: Microsoft.DesktopAppInstaller v1.21.3133.0

Winget Directories
-------------------------------------------------------------------------------------------------------------------------------
Logs                               %LOCALAPPDATA%\Packages\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\LocalState\DiagOutputDir
User Settings                      %LOCALAPPDATA%\Packages\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\LocalState\settings.json
Portable Links Directory (User)    %LOCALAPPDATA%\Microsoft\WinGet\Links
Portable Links Directory (Machine) C:\Program Files\WinGet\Links
Portable Package Root (User)       %LOCALAPPDATA%\Microsoft\WinGet\Packages
Portable Package Root              C:\Program Files\WinGet\Packages
Portable Package Root (x86)        C:\Program Files (x86)\WinGet\Packages
Installer Downloads                %USERPROFILE%\Downloads

Links
---------------------------------------------------------------------------
Privacy Statement   https://aka.ms/winget-privacy
License Agreement   https://aka.ms/winget-license
Third Party Notices https://aka.ms/winget-3rdPartyNotice
Homepage            https://aka.ms/winget
Windows Store Terms https://www.microsoft.com/en-us/storedocs/terms-of-sale

Admin Setting                             State
--------------------------------------------------
LocalManifestFiles                        Disabled
BypassCertificatePinningForMicrosoftStore Disabled
InstallerHashOverride                     Disabled
LocalArchiveMalwareScanOverride           Disabled

Seems winget is uninstallable :)

golfalot commented 8 months ago

Getting 0x80070005 : unknown error on winget uninstall when --scope machine is specified despite being local admin. Microsoft store working OK.

PS C:\Users\admin> Get-LocalGroupMember -Group "Administrators"

ObjectClass Name                          PrincipalSource
----------- ----                          ---------------
User        DESKTOP-GRLIE89\admin         Local
User        DESKTOP-GRLIE89\Administrator Local

PS C:\Users\admin> winget -v
v1.6.3482

Installation goes ok

PS C:\Users\admin> winget install --exact --id Giorgiotani.Peazip --silent --accept-package-agreements --accept-source-agreements --scope machine
 --version 9.5.0
Found PeaZip [Giorgiotani.Peazip] Version 9.5.0
This application is licensed to you by its owner.
Microsoft is not responsible for, nor does it grant any licenses to, third-party packages.
Downloading https://github.com/peazip/PeaZip/releases/download/9.5.0/peazip-9.5.0.WIN64.exe
  ██████████████████████████████  9.03 MB / 9.03 MB
Successfully verified installer hash
Starting package install...
Successfully installed

But uninstall fails

PS C:\Users\admin> winget uninstall --exact --id Giorgiotani.Peazip --silent --accept-source-agreements --scope machine --version 9.5.0
Failed to open the predefined source; please report to winget maintainers.
An unexpected error occurred while executing the command:
0x80070005 : unknown error

Reduce it to minimal case

PS C:\Users\admin> winget uninstall --exact --id Giorgiotani.Peazip --scope machine
Failed to open the predefined source; please report to winget maintainers.
An unexpected error occurred while executing the command:
0x80070005 : unknown error

This works OK, when not specifying --scope machine

PS C:\Users\admin> winget uninstall --exact --id Giorgiotani.Peazip --silent --accept-source-agreements --version 9.5.0
Found PeaZip [Giorgiotani.Peazip]
Starting package uninstall...
Successfully uninstalled

Also amusingly

PS C:\Users\admin> winget source reset --force
This command requires administrator privileges to execute.
gotounix commented 6 months ago

Using --scope machine should have permission:

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Confirm

Or using administrator run PowerShell.

piotrminkina commented 5 months ago

The problem still exists in Windows Package Manager v1.7.10582 in PowerShell version 5.1.22621.2506.

> Get-LocalGroupMember -Group "Administrators"

ObjectClass Name                 PrincipalSource
----------- ----                 ---------------
User        Orilla\Administrator Local
User        ORILLA\Piotrek       MicrosoftAccount

> Get-ExecutionPolicy
RemoteSigned

> winget list --exact Git.Git --scope machine
Failed to open the predefined source; please report to winget maintainers.
An unexpected error occurred while executing the command:
0x80070005 : unknown error