mirror of
https://github.com/ChrisTitusTech/winutil
synced 2026-02-04 06:50:09 +00:00
Add Create Bootable USB (#18)
* Add Create Bootable USB * Apply suggestion from @CodingWonders --------- Co-authored-by: CodingWonders <101426328+CodingWonders@users.noreply.github.com>
This commit is contained in:
@@ -55,6 +55,7 @@ public class PowerManagement {
|
|||||||
Write-Host "Index chosen: '$index' from $($sync.MicrowinWindowsFlavors.SelectedValue)"
|
Write-Host "Index chosen: '$index' from $($sync.MicrowinWindowsFlavors.SelectedValue)"
|
||||||
|
|
||||||
$copyToUSB = $sync.WPFMicrowinCopyToUsb.IsChecked
|
$copyToUSB = $sync.WPFMicrowinCopyToUsb.IsChecked
|
||||||
|
$bootable = $sync.WPFMicrowinBootable.IsChecked
|
||||||
$injectDrivers = $sync.MicrowinInjectDrivers.IsChecked
|
$injectDrivers = $sync.MicrowinInjectDrivers.IsChecked
|
||||||
$importDrivers = $sync.MicrowinImportDrivers.IsChecked
|
$importDrivers = $sync.MicrowinImportDrivers.IsChecked
|
||||||
|
|
||||||
@@ -628,6 +629,12 @@ public class PowerManagement {
|
|||||||
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." }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($bootable) {
|
||||||
|
Write-Host "Making Bootable USB drive"
|
||||||
|
Microwin-BootableUSB("$($SaveDialog.FileName)")
|
||||||
|
if ($?) { Write-Host "Done making bootable USB drive!" } else { Write-Host "Bootable USB creation failed." }
|
||||||
|
}
|
||||||
|
|
||||||
Write-Host " _____ "
|
Write-Host " _____ "
|
||||||
Write-Host "(____ \ "
|
Write-Host "(____ \ "
|
||||||
Write-Host " _ \ \ ___ ____ ____ "
|
Write-Host " _ \ \ ___ ____ ____ "
|
||||||
|
|||||||
58
functions/microwin/Microwin-BootableUSB.ps1
Normal file
58
functions/microwin/Microwin-BootableUSB.ps1
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
function MicroWin-BootableUSB {
|
||||||
|
[CmdletBinding()]
|
||||||
|
param (
|
||||||
|
[Parameter(Mandatory=$true)]
|
||||||
|
[string]$IsoPath
|
||||||
|
)
|
||||||
|
|
||||||
|
$TargetDisk = Get-Disk | Where-Object { $_.BusType -eq 'USB' -and $_.OperationalStatus -eq 'Online' } |
|
||||||
|
Sort-Object Number |
|
||||||
|
Out-GridView -Title "MicroWin: Select Target USB Drive" -OutputMode Single
|
||||||
|
|
||||||
|
if (-not $TargetDisk) {
|
||||||
|
Write-Warning "No USB drive selected. Operation cancelled."
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
$msgTitle = "MicroWin USB Warning"
|
||||||
|
$msgText = "WARNING: ALL DATA ON DISK $($TargetDisk.Number) WILL BE DELETED!`n`nAre you sure you want to proceed?"
|
||||||
|
$msgIcon = [System.Windows.MessageBoxImage]::Warning
|
||||||
|
$msgButton = [System.Windows.MessageBoxButton]::YesNo
|
||||||
|
|
||||||
|
$Response = [System.Windows.MessageBox]::Show($msgText, $msgTitle, $msgButton, $msgIcon)
|
||||||
|
if ($Response -ne "Yes") {
|
||||||
|
Write-Warning "Operation cancelled by user."
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Write-Host "Cleaning Disk $($TargetDisk.Number)..." -ForegroundColor Yellow
|
||||||
|
$TargetDisk | Clear-Disk -RemoveData -Confirm:$false
|
||||||
|
$TargetDisk | Initialize-Disk -PartitionStyle GPT -PassThru -ErrorAction SilentlyContinue | Out-Null
|
||||||
|
|
||||||
|
Write-Host "Creating NTFS Partition..." -ForegroundColor Yellow
|
||||||
|
$Partition = New-Partition -DiskNumber $TargetDisk.Number -UseMaximumSize -AssignDriveLetter
|
||||||
|
$USBLetter = "$($Partition.DriveLetter):"
|
||||||
|
|
||||||
|
Format-Volume -DriveLetter $Partition.DriveLetter -FileSystem NTFS -NewFileSystemLabel "MicroWin" -Confirm:$false
|
||||||
|
|
||||||
|
Write-Host "Mounting ISO: $IsoPath" -ForegroundColor Cyan
|
||||||
|
$Mount = Mount-DiskImage -ImagePath $IsoPath -PassThru
|
||||||
|
$IsoLetter = ($Mount | Get-Volume).DriveLetter + ":"
|
||||||
|
|
||||||
|
Write-Host "Copying files to $USBLetter (this may take a few minutes)..." -ForegroundColor Cyan
|
||||||
|
Copy-Files "$($IsoLetter)" "$($USBLetter)" -Recurse -Force
|
||||||
|
|
||||||
|
if (Test-Path "$IsoLetter\boot\bootsect.exe") {
|
||||||
|
Write-Host "Applying Boot Code..." -ForegroundColor Green
|
||||||
|
Set-Location "$IsoLetter\boot"
|
||||||
|
./bootsect.exe /nt60 "$USBLetter" /force /mbr
|
||||||
|
}
|
||||||
|
|
||||||
|
Dismount-DiskImage -ImagePath $IsoPath
|
||||||
|
Write-Host "SUCCESS: MicroWin USB created on $USBLetter" -ForegroundColor Green
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Error "Failed to create USB: $($_.Exception.Message)"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1459,6 +1459,7 @@
|
|||||||
<CheckBox Name="MicrowinCopyVirtIO" Content="Include VirtIO drivers" Margin="{DynamicResource MicrowinCheckBoxMargin}" IsChecked="False" ToolTip="Copy VirtIO Guest Tools drivers to your ISO file. Check this only if you want to use it on QEMU/Proxmox VE"/>
|
<CheckBox Name="MicrowinCopyVirtIO" Content="Include VirtIO drivers" Margin="{DynamicResource MicrowinCheckBoxMargin}" IsChecked="False" ToolTip="Copy VirtIO Guest Tools drivers to your ISO file. Check this only if you want to use it on QEMU/Proxmox VE"/>
|
||||||
<Rectangle Fill="{DynamicResource MainForegroundColor}" Height="2" HorizontalAlignment="Stretch" Margin="0,10,0,10"/>
|
<Rectangle Fill="{DynamicResource MainForegroundColor}" Height="2" HorizontalAlignment="Stretch" Margin="0,10,0,10"/>
|
||||||
<CheckBox Name="WPFMicrowinCopyToUsb" Content="Copy to Ventoy" Margin="{DynamicResource MicrowinCheckBoxMargin}" IsChecked="False" ToolTip="Copy to USB disk with a label Ventoy"/>
|
<CheckBox Name="WPFMicrowinCopyToUsb" Content="Copy to Ventoy" Margin="{DynamicResource MicrowinCheckBoxMargin}" IsChecked="False" ToolTip="Copy to USB disk with a label Ventoy"/>
|
||||||
|
<CheckBox Name="WPFMicrowinBootable" Content="Make Bootable USB" Margin="{DynamicResource MicrowinCheckBoxMargin}" IsChecked="False" ToolTip="Make the USB drive bootable"/>
|
||||||
<Rectangle Fill="{DynamicResource MainForegroundColor}" Height="2" HorizontalAlignment="Stretch" Margin="0,10,0,10"/>
|
<Rectangle Fill="{DynamicResource MainForegroundColor}" Height="2" HorizontalAlignment="Stretch" Margin="0,10,0,10"/>
|
||||||
<TextBlock Margin="6" Padding="1" TextWrapping="Wrap"><Bold>Custom user settings (leave empty for default user)</Bold></TextBlock>
|
<TextBlock Margin="6" Padding="1" TextWrapping="Wrap"><Bold>Custom user settings (leave empty for default user)</Bold></TextBlock>
|
||||||
<TextBlock Margin="6" Padding="1" TextWrapping="Wrap">User name (20 characters max.):</TextBlock>
|
<TextBlock Margin="6" Padding="1" TextWrapping="Wrap">User name (20 characters max.):</TextBlock>
|
||||||
|
|||||||
Reference in New Issue
Block a user