mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2024-11-14 22:55:52 -06:00
Exit Codes and Win32 API calls (#2462)
- Change process code to Start-Process -PassThru, finally removing the need for a new process object - Add code if ISO generation is not successful to display an error message in the system language from the Windows APIs
This commit is contained in:
parent
3929459106
commit
514eddd0b6
@ -453,22 +453,16 @@ public class PowerManagement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Write-Host "[INFO] Using oscdimg.exe from: $oscdimgPath"
|
Write-Host "[INFO] Using oscdimg.exe from: $oscdimgPath"
|
||||||
#& oscdimg.exe -m -o -u2 -udfver102 -bootdata:2#p0,e,b$mountDir\boot\etfsboot.com#pEF,e,b$mountDir\efi\microsoft\boot\efisys.bin $mountDir $env:temp\microwin.iso
|
|
||||||
#Start-Process -FilePath $oscdimgPath -ArgumentList "-m -o -u2 -udfver102 -bootdata:2#p0,e,b$mountDir\boot\etfsboot.com#pEF,e,b$mountDir\efi\microsoft\boot\efisys.bin $mountDir $env:temp\microwin.iso" -NoNewWindow -Wait
|
$oscdimgProc = Start-Process -FilePath "$oscdimgPath" -ArgumentList "-m -o -u2 -udfver102 -bootdata:2#p0,e,b$mountDir\boot\etfsboot.com#pEF,e,b$mountDir\efi\microsoft\boot\efisys.bin `"$mountDir`" `"$($SaveDialog.FileName)`"" -Wait -PassThru -NoNewWindow
|
||||||
#Start-Process -FilePath $oscdimgPath -ArgumentList '-m -o -u2 -udfver102 -bootdata:2#p0,e,b$mountDir\boot\etfsboot.com#pEF,e,b$mountDir\efi\microsoft\boot\efisys.bin $mountDir `"$($SaveDialog.FileName)`"' -NoNewWindow -Wait
|
|
||||||
$oscdimgProc = New-Object System.Diagnostics.Process
|
$LASTEXITCODE = $oscdimgProc.ExitCode
|
||||||
$oscdimgProc.StartInfo.FileName = $oscdimgPath
|
|
||||||
$oscdimgProc.StartInfo.Arguments = "-m -o -u2 -udfver102 -bootdata:2#p0,e,b$mountDir\boot\etfsboot.com#pEF,e,b$mountDir\efi\microsoft\boot\efisys.bin $mountDir `"$($SaveDialog.FileName)`""
|
Write-Host "OSCDIMG Error Level : $($oscdimgProc.ExitCode)"
|
||||||
$oscdimgProc.StartInfo.CreateNoWindow = $True
|
|
||||||
$oscdimgProc.StartInfo.WindowStyle = "Hidden"
|
|
||||||
$oscdimgProc.StartInfo.UseShellExecute = $False
|
|
||||||
$oscdimgProc.Start()
|
|
||||||
$oscdimgProc.WaitForExit()
|
|
||||||
|
|
||||||
if ($copyToUSB)
|
if ($copyToUSB)
|
||||||
{
|
{
|
||||||
Write-Host "Copying target ISO to the USB drive"
|
Write-Host "Copying target ISO to the USB drive"
|
||||||
#Copy-ToUSB("$env:temp\microwin.iso")
|
|
||||||
Copy-ToUSB("$($SaveDialog.FileName)")
|
Copy-ToUSB("$($SaveDialog.FileName)")
|
||||||
if ($?) { Write-Host "Done Copying target ISO to USB drive!" } else { Write-Host "ISO copy failed." }
|
if ($?) { Write-Host "Done Copying target ISO to USB drive!" } else { Write-Host "ISO copy failed." }
|
||||||
}
|
}
|
||||||
@ -485,13 +479,23 @@ public class PowerManagement {
|
|||||||
Write-Host "`n`nPerforming Cleanup..."
|
Write-Host "`n`nPerforming Cleanup..."
|
||||||
Remove-Item -Recurse -Force "$($scratchDir)"
|
Remove-Item -Recurse -Force "$($scratchDir)"
|
||||||
Remove-Item -Recurse -Force "$($mountDir)"
|
Remove-Item -Recurse -Force "$($mountDir)"
|
||||||
#$msg = "Done. ISO image is located here: $env:temp\microwin.iso"
|
|
||||||
$msg = "Done. ISO image is located here: $($SaveDialog.FileName)"
|
$msg = "Done. ISO image is located here: $($SaveDialog.FileName)"
|
||||||
Write-Host $msg
|
Write-Host $msg
|
||||||
Set-WinUtilTaskbaritem -state "None" -overlay "checkmark"
|
Set-WinUtilTaskbaritem -state "None" -overlay "checkmark"
|
||||||
[System.Windows.MessageBox]::Show($msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Information)
|
[System.Windows.MessageBox]::Show($msg, "Winutil", [System.Windows.MessageBoxButton]::OK, [System.Windows.MessageBoxImage]::Information)
|
||||||
} else {
|
} else {
|
||||||
Write-Host "ISO creation failed. The "$($mountDir)" directory has not been removed."
|
Write-Host "ISO creation failed. The "$($mountDir)" directory has not been removed."
|
||||||
|
try
|
||||||
|
{
|
||||||
|
# This creates a new Win32 exception from which we can extract a message in the system language.
|
||||||
|
# Now, this will NOT throw an exception
|
||||||
|
$exitCode = New-Object System.ComponentModel.Win32Exception($LASTEXITCODE)
|
||||||
|
Write-Host "Reason: $($exitCode.Message)"
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
# Could not get error description from Windows APIs
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$sync.MicrowinOptionsPanel.Visibility = 'Collapsed'
|
$sync.MicrowinOptionsPanel.Visibility = 'Collapsed'
|
||||||
|
Loading…
Reference in New Issue
Block a user