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

`winget export` failing with `Element not found` error #4545

Closed lukargit closed 1 month ago

lukargit commented 3 months ago

Brief description of your issue

We are using WinGet to install applications machine wide with Powershell DSC, and one of the test scripts is failing during the execution of winget export with this error:

2024-06-06 20:21:27.789 [REPO] Opened SQLite Index with version [1.7], last write [2024-06-06 18:32:17.000]
2024-06-06 20:21:27.901 [REPO] Creating new SQLite Index with version [Latest] at ':memory:'
2024-06-06 20:21:27.905 [REPO] Reading MSI UpgradeCodes
2024-06-06 20:21:27.981 [REPO] Reading MSI UpgradeCodes
2024-06-06 20:21:28.016 [FAIL] WindowsPackageManager.dll!00007FF886D49503: LogHr(1) tid(3c18) 80070490 Element not found.

2024-06-06 20:21:28.201 [CLI ] Caught winrt::hresult_error: 0x80070490 : Element not found.

This is not a widespread issue and has only happened on one machine at this point, but it does reproduce 100% of the time on this machine. Note that winget is running under SYSTEM context.

Steps to reproduce

DSC runs (under SYSTEM context) winget.exe export --include-versions --no-vt --accept-source-agreements --disable-interactivity --output exportedApps.json during the test portion of a script resource, and that always fails with an Element not found error.

Expected behavior

The current list of installed applications is written to exportedApps.json

Actual behavior

The export fails and no file is written.

Environment

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

Windows: Windows.Desktop v10.0.22621.3593
System Architecture: X64
Package: Microsoft.DesktopAppInstaller v1.22.11261.0
github-actions[bot] commented 3 months ago

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!

Closed similar issues:

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

Trenly commented 3 months ago

Can you try running the export command outside of DSC? I'm almost certain this is an issue caused by WinGet being run in system context, so knowing if it works outside of a DSC script will help determine the root cause

lukargit commented 3 months ago

@Trenly it runs fine outside of DSC on the same machine. This same DSC config is working well on 350+ other machines, so running winget in system context is working well elsewhere. I can re-image the machine and likely resolve the issue for us, but I wanted to keep it around in case there is additional data that could be useful in getting to a root cause.

lukargit commented 3 months ago

Any updates on action we can take here to continue the investigation? This has started occurring on more machines after they are working fine for some time (weeks). Our only mitigation at this point is to reimage them, after which winget export works fine again.

denelon commented 2 months ago

Is this still happening with WinGet 1.8?

lukargit commented 1 month ago

@denelon we have not run into this since upgrading to 1.8.1911. At the rate it was occurring, if the bug still existed I would expect at least one machine to have run into it, so i'm good with closing this. I can create a new issue if we run into it again.

RobMSP commented 1 month ago

I have two systems, deployed with the same OS and tools. One is failing unless I run as the user, if I run as 'system' i get an error. The other works fine.

I checked the local security policy, couldn't find any differences. Same AV etc...

The only potential difference, is one has HyperV instaleld right now.

`PS C:\temp> winget --info
Windows Package Manager v1.8.1911
Copyright (c) Microsoft Corporation. All rights reserved.

Windows: Windows.Desktop v10.0.22631.4037
System Architecture: X64

Winget Directories
------------------------------------------------------------------------------------------------------
Logs                               %TEMP%\WinGet\defaultState
User Settings                      %LOCALAPPDATA%\Microsoft\WinGet\Settings\defaultState\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                C:\Users\Default\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
ProxyCommandLineOptions                   Disabled
DefaultProxy                              Disabled
PS C:\temp> whoami
nt authority\system
PS C:\temp> winget update
Name                            Id                            Version        Available     Source
-------------------------------------------------------------------------------------------------
Mozilla Firefox (x64 en-US)     Mozilla.Firefox               129.0.1        129.0.2       winget
Google Chrome                   Google.Chrome                 127.0.6533.120 128.0.6613.85 winget
Microsoft Edge WebView2 Runtime Microsoft.EdgeWebView2Runtime 127.0.2651.105 128.0.2739.42 winget
Microsoft Edge                  Microsoft.Edge                127.0.2651.105 128.0.2739.42 winget
4 upgrades available.`

System 2 -


`PS C:\Windows\system32> winget --info
Windows Package Manager v1.8.1911
Copyright (c) Microsoft Corporation. All rights reserved.

Windows: Windows.Desktop v10.0.22631.4037
System Architecture: X64

Winget Directories
------------------------------------------------------------------------------------------------------
Logs                               %TEMP%\WinGet\defaultState
User Settings                      %LOCALAPPDATA%\Microsoft\WinGet\Settings\defaultState\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                C:\Users\Default\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
ProxyCommandLineOptions                   Disabled
DefaultProxy                              Disabled
PS C:\Windows\system32> whoami
nt authority\system
PS C:\Windows\system32> winget update
Failed to open the predefined source; please report to winget maintainers.
An unexpected error occurred while executing the command:
0x80070490 : Element not found.
PS C:\Windows\system32> `