@@ -124,7 +124,15 @@ function Invoke-WinUtilISOMountAndVerify {
124124 [void ]$sync [" WPFWin11ISOEditionComboBox" ].Items.Add(" $ ( $img.ImageIndex ) : $ ( $img.ImageName ) " )
125125 }
126126 if ($sync [" WPFWin11ISOEditionComboBox" ].Items.Count -gt 0 ) {
127- $sync [" WPFWin11ISOEditionComboBox" ].SelectedIndex = 0
127+ # Default to Windows 11 Pro; fall back to first item if not found
128+ $proIndex = -1
129+ for ($i = 0 ; $i -lt $sync [" WPFWin11ISOEditionComboBox" ].Items.Count; $i ++ ) {
130+ if ($sync [" WPFWin11ISOEditionComboBox" ].Items[$i ] -match " Windows 11 Pro(?![\w ])" ) {
131+ $proIndex = $i
132+ break
133+ }
134+ }
135+ $sync [" WPFWin11ISOEditionComboBox" ].SelectedIndex = if ($proIndex -ge 0 ) { $proIndex } else { 0 }
128136 }
129137 })
130138 $sync [" WPFWin11ISOVerifyResultPanel" ].Visibility = " Visible"
@@ -513,11 +521,17 @@ function Invoke-WinUtilISOExport {
513521
514522 $outputISO = $dlg.FileName
515523 Write-Win11ISOLog " Exporting to ISO: $outputISO "
524+
516525 Set-WinUtilProgressBar - Label " Building ISO..." - Percent 10
517526
518- # Locate oscdimg.exe (Windows ADK)
527+ # Locate oscdimg.exe (Windows ADK or winget per-user install )
519528 $oscdimg = Get-ChildItem " C:\Program Files (x86)\Windows Kits" - Recurse - Filter " oscdimg.exe" - ErrorAction SilentlyContinue |
520529 Select-Object - First 1 - ExpandProperty FullName
530+ if (-not $oscdimg ) {
531+ $oscdimg = Get-ChildItem " $env: LOCALAPPDATA \Microsoft\WinGet\Packages" - Recurse - Filter " oscdimg.exe" - ErrorAction SilentlyContinue |
532+ Where-Object { $_.FullName -match ' Microsoft\.OSCDIMG' } |
533+ Select-Object - First 1 - ExpandProperty FullName
534+ }
521535
522536 if (-not $oscdimg ) {
523537 Write-Win11ISOLog " oscdimg.exe not found. Attempting to install via winget..."
@@ -526,8 +540,9 @@ function Invoke-WinUtilISOExport {
526540 $winget = Get-Command winget - ErrorAction Stop
527541 $result = & $winget install - e -- id Microsoft.OSCDIMG -- accept- package- agreements -- accept- source- agreements 2>&1
528542 Write-Win11ISOLog " winget output: $result "
529- # Re-scan for oscdimg after install
530- $oscdimg = Get-ChildItem " C:\Program Files (x86)\Windows Kits" - Recurse - Filter " oscdimg.exe" - ErrorAction SilentlyContinue |
543+ # Re-scan after install
544+ $oscdimg = Get-ChildItem " $env: LOCALAPPDATA \Microsoft\WinGet\Packages" - Recurse - Filter " oscdimg.exe" - ErrorAction SilentlyContinue |
545+ Where-Object { $_.FullName -match ' Microsoft\.OSCDIMG' } |
531546 Select-Object - First 1 - ExpandProperty FullName
532547 } catch {
533548 Write-Win11ISOLog " winget not available or install failed: $_ "
@@ -559,7 +574,31 @@ function Invoke-WinUtilISOExport {
559574
560575 try {
561576 Write-Win11ISOLog " Running oscdimg..."
562- $proc = Start-Process - FilePath $oscdimg - ArgumentList $oscdimgArgs - Wait - PassThru - NoNewWindow
577+ $psi = [System.Diagnostics.ProcessStartInfo ]::new()
578+ $psi.FileName = $oscdimg
579+ $psi.Arguments = $oscdimgArgs -join " "
580+ $psi.RedirectStandardOutput = $true
581+ $psi.RedirectStandardError = $true
582+ $psi.UseShellExecute = $false
583+ $psi.CreateNoWindow = $true
584+
585+ $proc = [System.Diagnostics.Process ]::new()
586+ $proc.StartInfo = $psi
587+ $proc.Start () | Out-Null
588+
589+ # Stream stdout and stderr line-by-line to the status log
590+ $stdoutTask = $proc.StandardOutput.ReadToEndAsync ()
591+ $stderrTask = $proc.StandardError.ReadToEndAsync ()
592+ $proc.WaitForExit ()
593+ [System.Threading.Tasks.Task ]::WaitAll($stdoutTask , $stderrTask )
594+
595+ foreach ($line in ($stdoutTask.Result -split " `r ?`n " )) {
596+ if ($line.Trim ()) { Write-Win11ISOLog $line }
597+ }
598+ foreach ($line in ($stderrTask.Result -split " `r ?`n " )) {
599+ if ($line.Trim ()) { Write-Win11ISOLog " [stderr]$line " }
600+ }
601+
563602 if ($proc.ExitCode -eq 0 ) {
564603 Set-WinUtilProgressBar - Label " ISO exported ✔" - Percent 100
565604 Write-Win11ISOLog " ISO exported successfully: $outputISO "
0 commit comments