winget-cli icon indicating copy to clipboard operation
winget-cli copied to clipboard

WinGet on Windows fails to install packages when run by automation, without human ever logging in

Open dmgonch opened this issue 1 year ago • 3 comments

Brief description of your issue

WinGet fails to install packages when run in 'headless' environment, i.e. solely by automation, without a human ever logging to the VM. In the repro case at hand, WinGet is invoked fully automatically from Windows service running under local admin account.

Steps to reproduce

Preconditions: Azure Windows VM that is configured to run upon creation a service under local admin account. A human never logs into the VM. The steps below are executed by the service from PowerShell 7:

Install-PackageProvider -Name NuGet -Force
Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted
[ Run WinGet install steps from https://learn.microsoft.com/en-us/windows/package-manager/winget/#install-winget-on-windows-sandbox ]
Add-AppxPackage 'https://cdn.winget.microsoft.com/cache/source.msix'
Install-Module Microsoft.WinGet.Client -Scope AllUsers -Force
Install-Module Microsoft.WinGet.Configuration -AllowPrerelease -Scope AllUsers -Force
Install-Module PSDscResources -Scope AllUsers -Force
Repair-WinGetPackageManager -Latest
winget install --id Microsoft.Azure.AZCopy.10 --exact --disable-interactivity --silent --no-upgrade --accept-package-agreements --accept-source-agreements --verbose-logs --scope machine

Expected behavior

No error and the package is successfully installed.

Actual behavior

winget.exe output:

Found AzCopy v10 [Microsoft.Azure.AZCopy.10] Version 10.22.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://azcopyvnext.azureedge.net/releases/release-10.22.0-20231205/azcopy_windows_amd64_10.22.0.zip Successfully verified installer hash Extracting archive... Failed to extract the contents of the archive

Relevant logs snippet:

DATE 00:15:20.000 [CORE] Downloading to path: C:\Users\testuser\AppData\Local\Temp\WinGet\Microsoft.Azure.AZCopy.10.10.22.0\b86dbc7323d3f27bbbff887b1cf22659d19f250d07090d3273a24e3a64e4055c ... DATE 00:15:20.621 [CORE] Download completed. ... DATE 00:15:20.766 [CLI ] Successfully renamed downloaded installer. Path: C:\Users\testuser\AppData\Local\Temp\WinGet\Microsoft.Azure.AZCopy.10.10.22.0\azcopy_windows_amd64_10.22.0.zip DATE 00:15:20.871 [CLI ] Extracting archive to: C:\Users\testuser\AppData\Local\Temp\WinGet\Microsoft.Azure.AZCopy.10.10.22.0\extracted DATE 00:15:21.044 [FAIL] C:__w\1\s\external\pkg\src\AppInstallerCommonCore\Archive.cpp(48)\WindowsPackageManager.dll!00007FFF8B442282: (caller: 00007FFF8B3BDCCC) ReturnHr(1) tid(1004) 80010105 The server threw an exception.

Environment

winget.exe --info

Copyright (c) Microsoft Corporation. All rights reserved. Windows: Windows.Desktop v10.0.22631.3007 System Architecture: X64 Package: Microsoft.DesktopAppInstaller v1.21.3482.0 Winget Directories

Logs %LOCALAPPDATA%\Packages\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\LocalState\Diag??? User Settings %LOCALAPPDATA%\Packages\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\LocalState\sett??? 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

Get-AppxPackage Microsoft.DesktopAppInstaller

Name : Microsoft.DesktopAppInstaller Publisher : CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US Architecture : X64 ResourceId : Version : 1.21.3482.0 PackageFullName : Microsoft.DesktopAppInstaller_1.21.3482.0_x64__8wekyb3d8bbwe InstallLocation : C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_1.21.3482.0_x64__8wekyb3d8bbwe IsFramework : False PackageFamilyName : Microsoft.DesktopAppInstaller_8wekyb3d8bbwe PublisherId : 8wekyb3d8bbwe IsResourcePackage : False IsBundle : False IsDevelopmentMode : False NonRemovable : True Dependencies : {Microsoft.UI.Xaml.2.7_7.2208.15002.0_x64__8wekyb3d8bbwe, Microsoft.VCLibs.140.00.UWPDesktop_14.0.33321.0_x64__8wekyb3d8bbwe, Microsoft.DesktopAppInstaller_1.21.3482.0_neutral_split.scale-100_8wekyb3d8bbwe} IsPartiallyStaged : False SignatureKind : Store Status : Ok

dmgonch avatar Feb 08 '24 04:02 dmgonch

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.

github-actions[bot] avatar Feb 08 '24 04:02 github-actions[bot]

@dmgonch,

Could you try using the Microsoft.WinGet.Client PowerShell module to install the package in the system context?

The cmdlet would be Install-WinGetPackage.

denelon avatar Mar 13 '24 16:03 denelon

@denelon Install-WinGetPackage fails as well. The command prints Failed to create instance: -2147023174 In WinGetCOM-[DATE-TIME].log file I see errors like below:

2024-03-13 18:20:40.922 [FAIL] C:\[SNIP]\pkg\src\WindowsPackageManager\main.cpp(61)\WindowsPackageManager.dll!00007FFF97BB4E15: (caller: 00007FF71B884E3F) ReturnHr(1) tid(68c) 80004015 The class is configured to run as a security id different from the caller
2024-03-13 18:20:40.922 [FAIL] C:\[SNIP]\pkg\src\WinGetServer\WinMain.cpp(136)\WindowsPackageManagerServer.exe!00007FF71B884E64: (caller: 00007FF71B8870D2) ReturnHr(1) tid(68c) 80004015 The class is configured to run as a security id different from the caller

dmgonch avatar Mar 13 '24 20:03 dmgonch

For my case, setting archiveExtractionMethod to tar resolves this issue. https://github.com/microsoft/winget-cli/blob/master/doc/Settings.md#archive-extraction-method

dmgonch avatar Jul 17 '24 00:07 dmgonch