microsoft / microsoft/winget-cli

Winget doesn't work in packer due to user-only installs versus sysprep

Open
#5,599 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Context-System Issue-Bug
Dominant language
C++
Stars
26.4k
Forks
1.8k
Avg merge
1d 11h
Merged PRs (30d)
15

Description

Brief description of your issue

If you install winget and particularly the winget sources package during a packer build, then sysprep will hang forever at IMAGE_STATE_COMPLETE, but never reaches the IMAGE_STATE_GENERALIZE_RESEAL_TO_OOBE state.

I got some logs from Sysprep:

(note: Package Microsoft.Winget.Source_2025.718.1153.54_neutral__8wekyb3d8bbwe was installed for a user, but not provisioned for all users. This package will not function properly in the sysprep image.)

2025-07-18T11:43:44Z: ==> windows-custom.azure-arm.windows-custom: Sysprep encountered errors. Review the setuperr.log for details.
2025-07-18T11:43:44Z: ==> windows-custom.azure-arm.windows-custom: 2025-06-07 09:52:50, Error                 SYSPRP BCD: BiUpdateEfiEntry failed c000000d
2025-07-18T11:43:44Z: ==> windows-custom.azure-arm.windows-custom: 2025-06-07 09:52:50, Error                 SYSPRP BCD: BiExportBcdObjects failed c000000d
2025-07-18T11:43:44Z: ==> windows-custom.azure-arm.windows-custom: 2025-06-07 09:52:50, Error                 SYSPRP BCD: BiExportStoreAlterationsToEfi failed c000000d
2025-07-18T11:43:44Z: ==> windows-custom.azure-arm.windows-custom: 2025-06-07 09:52:50, Error                 SYSPRP BCD: Failed to export alterations to firmware. Status: c000000d
2025-07-18T11:43:44Z: ==> windows-custom.azure-arm.windows-custom: 2025-06-17 12:41:38, Error                 SYSPRP BCD: BiUpdateEfiEntry failed c000000d
2025-07-18T11:43:44Z: ==> windows-custom.azure-arm.windows-custom: 2025-06-17 12:41:38, Error                 SYSPRP BCD: BiExportBcdObjects failed c000000d
2025-07-18T11:43:44Z: ==> windows-custom.azure-arm.windows-custom: 2025-06-17 12:41:38, Error                 SYSPRP BCD: BiExportStoreAlterationsToEfi failed c000000d
2025-07-18T11:43:44Z: ==> windows-custom.azure-arm.windows-custom: 2025-06-17 12:41:38, Error                 SYSPRP BCD: Failed to export alterations to firmware. Status: c000000d
2025-07-18T11:43:44Z: ==> windows-custom.azure-arm.windows-custom: 2025-06-17 12:41:41, Error                 SYSPRP GeneralizeForImaging for WaaSMedic failed to create WaaSRemediationAgent. hr = 0x80070422[gle=0x00000057]
2025-07-18T11:43:44Z: ==> windows-custom.azure-arm.windows-custom: 2025-07-18 11:33:41, Error                 SYSPRP Package Microsoft.Winget.Source_2025.718.1153.54_neutral__8wekyb3d8bbwe was installed for a user, but not provisioned for all users. This package will not function properly in the sysprep image.
2025-07-18T11:43:44Z: ==> windows-custom.azure-arm.windows-custom: 2025-07-18 11:33:41, Error                 SYSPRP Failed to remove apps for the current user: 0x80073cf2.
2025-07-18T11:43:44Z: ==> windows-custom.azure-arm.windows-custom: 2025-07-18 11:33:41, Error                 SYSPRP Exit code of RemoveAllApps thread was 0x3cf2.
2025-07-18T11:43:44Z: ==> windows-custom.azure-arm.windows-custom: 2025-07-18 11:33:41, Error                 SYSPRP ActionPlatform::LaunchModule: Failure occurred while executing 'SysprepGeneralizeValidate' from C:\Windows\System32\AppxSysprep.dll; dwRet = 0x3cf2
2025-07-18T11:43:44Z: ==> windows-custom.azure-arm.windows-custom: 2025-07-18 11:33:41, Error                 SYSPRP SysprepSession::Validate: Error in validating actions from C:\Windows\System32\Sysprep\ActionFiles\Generalize.xml; dwRet = 0x3cf2
2025-07-18T11:43:44Z: ==> windows-custom.azure-arm.windows-custom: 2025-07-18 11:33:41, Error                 SYSPRP RunPlatformActions:Failed while validating Sysprep session actions; dwRet = 0x3cf2
2025-07-18T11:43:44Z: ==> windows-custom.azure-arm.windows-custom: 2025-07-18 11:33:41, Error      [0x0f0070] SYSPRP RunDlls:An error occurred while running registry sysprep DLLs, halting sysprep execution. dwRet = 0x3cf2
2025-07-18T11:43:44Z: ==> windows-custom.azure-arm.windows-custom: 2025-07-18 11:33:41, Error      [0x0f00d8] SYSPRP WinMain:Hit failure while pre-validate sysprep generalize internal providers; hr = 0x80073cf2
Steps to reproduce
build {
  sources = ["source.azure-arm.windows-11-golden"] # it's win11-24h2-pron
  name   = "windows-broken"

  provisioner "powershell" {
    inline = ["Set-ExecutionPolicy Bypass -Scope Process -Force"]
  }

  # install winget
  provisioner "powershell" {
    inline = [
      "Add-AppxPackage -Path https://cdn.winget.microsoft.com/cache/source.msix",
      "Add-AppxPackage -RegisterByFamilyName -MainPackage Microsoft.DesktopAppInstaller_8wekyb3d8bbwe",
      "winget --info"
    ]
  }

  provisioner "windows-restart" {
    restart_check_command = "powershell -command \"& {Write-Output 'restarted.'}\""
  }

# sysprep as per https://learn.microsoft.com/en-us/azure/virtual-machines/windows/build-image-with-packer#create-a-vm-from-the-packer-image 
# will hang forever
  provisioner "powershell" {
    inline = ["while ((Get-Service RdAgent).Status -ne 'Running') { Start-Sleep -s 5 }", "while ((Get-Service WindowsAzureGuestAgent).Status -ne 'Running') { Start-Sleep -s 5 }", "& $env:SystemRoot\\System32\\Sysprep\\Sysprep.exe /oobe /generalize /quiet /quit", "while($true) { $imageState = Get-ItemProperty HKLM:\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Setup\\State | Select ImageState; if($imageState.ImageState -ne 'IMAGE_STATE_GENERALIZE_RESEAL_TO_OOBE') { Write-Output $imageState.ImageState; Start-Sleep -s 10  } else { break } }"]
  }
}
Expected behavior
  • winget and sources should be able to be installed systemwide, so that it can be installed in a way that doesn't break sysprep
Actual behavior
  • winget and sources cannot be installed outside of scope:user, and breaks sysprep
Environment
2025-07-18T11:29:23Z: ==> windows-custom.azure-arm.windows-broken: Windows Package Manager v1.9.25200
2025-07-18T11:29:23Z: ==> windows-custom.azure-arm.windows-broken: Copyright (c) Microsoft Corporation. All rights reserved.
2025-07-18T11:29:23Z: ==> windows-custom.azure-arm.windows-broken:
2025-07-18T11:29:23Z: ==> windows-custom.azure-arm.windows-broken: Windows: Windows.Desktop v10.0.26100.4349
2025-07-18T11:29:23Z: ==> windows-custom.azure-arm.windows-broken: System Architecture: X64
2025-07-18T11:29:23Z: ==> windows-custom.azure-arm.windows-broken: Package: Microsoft.DesktopAppInstaller v1.24.25199.0
2025-07-18T11:29:23Z: ==> windows-custom.azure-arm.windows-broken:
2025-07-18T11:29:23Z: ==> windows-custom.azure-arm.windows-broken: Winget Directories
2025-07-18T11:29:23Z: ==> windows-custom.azure-arm.windows-broken: -----------------------------------------------------------------------------------------------------------------------
2025-07-18T11:29:23Z: ==> windows-custom.azure-arm.windows-broken: Logs                               %LOCALAPPDATA%\Packages\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\LocalState\Diag…
2025-07-18T11:29:23Z: ==> windows-custom.azure-arm.windows-broken: User Settings                      %LOCALAPPDATA%\Packages\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe\LocalState\sett…
2025-07-18T11:29:23Z: ==> windows-custom.azure-arm.windows-broken: Portable Links Directory (User)    %LOCALAPPDATA%\Microsoft\WinGet\Links
2025-07-18T11:29:23Z: ==> windows-custom.azure-arm.windows-broken: Portable Links Directory (Machine) C:\Program Files\WinGet\Links
2025-07-18T11:29:23Z: ==> windows-custom.azure-arm.windows-broken: Portable Package Root (User)       %LOCALAPPDATA%\Microsoft\WinGet\Packages
2025-07-18T11:29:23Z: ==> windows-custom.azure-arm.windows-broken: Portable Package Root              C:\Program Files\WinGet\Packages
2025-07-18T11:29:23Z: ==> windows-custom.azure-arm.windows-broken: Portable Package Root (x86)        C:\Program Files (x86)\WinGet\Packages
2025-07-18T11:29:23Z: ==> windows-custom.azure-arm.windows-broken: Installer Downloads                %USERPROFILE%\Downloads
2025-07-18T11:29:23Z: ==> windows-custom.azure-arm.windows-broken:
2025-07-18T11:29:23Z: ==> windows-custom.azure-arm.windows-broken: Links
2025-07-18T11:29:23Z: ==> windows-custom.azure-arm.windows-broken: ---------------------------------------------------------------------------
2025-07-18T11:29:23Z: ==> windows-custom.azure-arm.windows-broken: Privacy Statement   https://aka.ms/winget-privacy
2025-07-18T11:29:23Z: ==> windows-custom.azure-arm.windows-broken: License Agreement   https://aka.ms/winget-license
2025-07-18T11:29:23Z: ==> windows-custom.azure-arm.windows-broken: Third Party Notices https://aka.ms/winget-3rdPartyNotice
2025-07-18T11:29:23Z: ==> windows-custom.azure-arm.windows-broken: Homepage            https://aka.ms/winget
2025-07-18T11:29:23Z: ==> windows-custom.azure-arm.windows-broken: Windows Store Terms https://www.microsoft.com/en-us/storedocs/terms-of-sale
2025-07-18T11:29:23Z: ==> windows-custom.azure-arm.windows-broken:
2025-07-18T11:29:23Z: ==> windows-custom.azure-arm.windows-broken: Admin Setting                             State
2025-07-18T11:29:23Z: ==> windows-custom.azure-arm.windows-broken: --------------------------------------------------
2025-07-18T11:29:23Z: ==> windows-custom.azure-arm.windows-broken: LocalManifestFiles                        Disabled
2025-07-18T11:29:23Z: ==> windows-custom.azure-arm.windows-broken: BypassCertificatePinningForMicrosoftStore Disabled
2025-07-18T11:29:23Z: ==> windows-custom.azure-arm.windows-broken: InstallerHashOverride                     Disabled
2025-07-18T11:29:23Z: ==> windows-custom.azure-arm.windows-broken: LocalArchiveMalwareScanOverride           Disabled
2025-07-18T11:29:24Z: ==> windows-custom.azure-arm.windows-broken: ProxyCommandLineOptions                   Disabled
2025-07-18T11:29:24Z: ==> windows-custom.azure-arm.windows-broken: DefaultProxy                              Disabled

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Packer HCL reproducer, especially the Add-AppxPackage commands and the Sysprep.exe /oobe /generalize invocation, then review the supplied Sysprep errors for the user-only Microsoft.Winget.Source package. Done means winget and its sources can be installed systemwide in the shown Windows image without Sysprep hanging before IMAGE_STATE_GENERALIZE_RESEAL_TO_OOBE.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, powershell
Domain
cli, cloud, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.