diff --git a/template/Install-CIToolchain-WinBuild2022.ps1 b/template/Install-CIToolchain-WinBuild2022.ps1 index a45b31f..b175ffd 100644 --- a/template/Install-CIToolchain-WinBuild2022.ps1 +++ b/template/Install-CIToolchain-WinBuild2022.ps1 @@ -280,12 +280,19 @@ function Invoke-DiskCleanup { } catch { Write-Warning "wuauserv pre-DISM ACL deny skipped (non-fatal): $_" } + # Use the ScheduledTasks cmdlets (not schtasks.exe): a missing task makes + # schtasks write to stderr and exit 1, which — under EAP=Stop and the + # exit-code-sensitive cleanup wrapper — leaks $LASTEXITCODE=1 and fails the + # whole step. The cmdlets just no-op silently when the task is absent. foreach ($t in @( '\Microsoft\Windows\WindowsUpdate\Scheduled Start', '\Microsoft\Windows\UpdateOrchestrator\Schedule Scan', '\Microsoft\Windows\UpdateOrchestrator\Schedule Scan Static Task' )) { - schtasks /Change /TN $t /Disable 2>&1 | Out-Null + $leaf = Split-Path $t -Leaf + $path = (Split-Path $t -Parent) + '\' + Get-ScheduledTask -TaskPath $path -TaskName $leaf -ErrorAction SilentlyContinue | + Disable-ScheduledTask -ErrorAction SilentlyContinue | Out-Null } $sdDownload = 'C:\Windows\SoftwareDistribution\Download' diff --git a/template/Install-CIToolchain-WinBuild2025.ps1 b/template/Install-CIToolchain-WinBuild2025.ps1 index 82ef2b5..d598193 100644 --- a/template/Install-CIToolchain-WinBuild2025.ps1 +++ b/template/Install-CIToolchain-WinBuild2025.ps1 @@ -281,12 +281,19 @@ function Invoke-DiskCleanup { } catch { Write-Warning "wuauserv pre-DISM ACL deny skipped (non-fatal): $_" } + # Use the ScheduledTasks cmdlets (not schtasks.exe): a missing task makes + # schtasks write to stderr and exit 1, which — under EAP=Stop and the + # exit-code-sensitive cleanup wrapper — leaks $LASTEXITCODE=1 and fails the + # whole step. The cmdlets just no-op silently when the task is absent. foreach ($t in @( '\Microsoft\Windows\WindowsUpdate\Scheduled Start', '\Microsoft\Windows\UpdateOrchestrator\Schedule Scan', '\Microsoft\Windows\UpdateOrchestrator\Schedule Scan Static Task' )) { - schtasks /Change /TN $t /Disable 2>&1 | Out-Null + $leaf = Split-Path $t -Leaf + $path = (Split-Path $t -Parent) + '\' + Get-ScheduledTask -TaskPath $path -TaskName $leaf -ErrorAction SilentlyContinue | + Disable-ScheduledTask -ErrorAction SilentlyContinue | Out-Null } $sdDownload = 'C:\Windows\SoftwareDistribution\Download'