mirror of
https://github.com/ChrisTitusTech/winutil
synced 2026-04-05 22:28:31 +00:00
Compare commits
10 Commits
410d3c5056
...
d0012449ad
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d0012449ad | ||
|
|
18594f6d2d | ||
|
|
50c4398394 | ||
|
|
ed5ec52767 | ||
|
|
319ee4e555 | ||
|
|
2ef7f2deb9 | ||
|
|
cca9bee107 | ||
|
|
669ecd9c64 | ||
|
|
64ea075727 | ||
|
|
773ea3a950 |
@@ -261,6 +261,7 @@ function Invoke-WinUtilISOModify {
|
||||
$sync["WPFWin11ISOStatusLog"].CaretIndex = $sync["WPFWin11ISOStatusLog"].Text.Length
|
||||
$sync["WPFWin11ISOStatusLog"].ScrollToEnd()
|
||||
})
|
||||
Add-Content -Path (Join-Path $workDir "WinUtil_Win11ISO.log") -Value "[$ts] $msg" -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
function SetProgress($label, $pct) {
|
||||
@@ -376,6 +377,7 @@ function Invoke-WinUtilISOModify {
|
||||
# the UI thread here.
|
||||
$sync["WPFWin11ISOOutputSection"].Dispatcher.Invoke([action]{
|
||||
$sync["WPFWin11ISOOutputSection"].Visibility = "Visible"
|
||||
$sync["WPFWin11ISOStatusLog"].Height = 300
|
||||
})
|
||||
}
|
||||
catch {
|
||||
@@ -480,12 +482,13 @@ function Invoke-WinUtilISOCheckExistingWork {
|
||||
$sync["WPFWin11ISOMountSection"].Visibility = "Collapsed"
|
||||
$sync["WPFWin11ISOModifySection"].Visibility = "Collapsed"
|
||||
$sync["WPFWin11ISOOutputSection"].Visibility = "Visible"
|
||||
$sync["WPFWin11ISOStatusLog"].Height = 300
|
||||
|
||||
# Notify via the status log
|
||||
$dirName = $existingWorkDir.Name
|
||||
$modified = $existingWorkDir.LastWriteTime.ToString("yyyy-MM-dd HH:mm")
|
||||
Write-Win11ISOLog "Existing working directory found: $($existingWorkDir.FullName)"
|
||||
Write-Win11ISOLog "Last modified: $modified — Skipping Steps 1-3 and resuming at Step 4."
|
||||
Write-Win11ISOLog "Last modified: $modified - Skipping Steps 1-3 and resuming at Step 4."
|
||||
Write-Win11ISOLog "Click 'Clean & Reset' if you want to start over with a new ISO."
|
||||
|
||||
[System.Windows.MessageBox]::Show(
|
||||
@@ -498,6 +501,8 @@ function Invoke-WinUtilISOCleanAndReset {
|
||||
.SYNOPSIS
|
||||
Deletes the temporary working directory created during ISO modification
|
||||
and resets the entire ISO UI back to its initial state (Step 1 only).
|
||||
Deletion runs in a background runspace so the UI stays responsive and
|
||||
progress is reported to the user.
|
||||
#>
|
||||
|
||||
$workDir = $sync["Win11ISOWorkDir"]
|
||||
@@ -507,37 +512,133 @@ function Invoke-WinUtilISOCleanAndReset {
|
||||
"This will delete the temporary working directory:`n`n$workDir`n`nAnd reset the interface back to the start.`n`nContinue?",
|
||||
"Clean & Reset", "YesNo", "Warning")
|
||||
if ($confirm -ne "Yes") { return }
|
||||
|
||||
try {
|
||||
Write-Win11ISOLog "Deleting temp directory: $workDir"
|
||||
Remove-Item -Path $workDir -Recurse -Force -ErrorAction Stop
|
||||
Write-Win11ISOLog "Temp directory deleted."
|
||||
} catch {
|
||||
Write-Win11ISOLog "WARNING: could not fully delete temp directory: $_"
|
||||
}
|
||||
}
|
||||
|
||||
# Clear all stored ISO state
|
||||
$sync["Win11ISOWorkDir"] = $null
|
||||
$sync["Win11ISOContentsDir"] = $null
|
||||
$sync["Win11ISOImagePath"] = $null
|
||||
$sync["Win11ISODriveLetter"] = $null
|
||||
$sync["Win11ISOWimPath"] = $null
|
||||
$sync["Win11ISOImageInfo"] = $null
|
||||
$sync["Win11ISOUSBDisks"] = $null
|
||||
# Disable button so it cannot be clicked twice
|
||||
$sync["WPFWin11ISOCleanResetButton"].IsEnabled = $false
|
||||
|
||||
# Reset the UI to the initial state
|
||||
$sync["WPFWin11ISOPath"].Text = "No ISO selected..."
|
||||
$sync["WPFWin11ISOFileInfo"].Visibility = "Collapsed"
|
||||
$sync["WPFWin11ISOVerifyResultPanel"].Visibility = "Collapsed"
|
||||
$sync["WPFWin11ISOOptionUSB"].Visibility = "Collapsed"
|
||||
$sync["WPFWin11ISOOutputSection"].Visibility = "Collapsed"
|
||||
$sync["WPFWin11ISOModifySection"].Visibility = "Collapsed"
|
||||
$sync["WPFWin11ISOMountSection"].Visibility = "Collapsed"
|
||||
$sync["WPFWin11ISOSelectSection"].Visibility = "Visible"
|
||||
$sync["WPFWin11ISOStatusLog"].Text = "Ready. Please select a Windows 11 ISO to begin."
|
||||
$sync["WPFWin11ISOStatusLog"].Height = 140
|
||||
$sync["WPFWin11ISOModifyButton"].IsEnabled = $true
|
||||
$runspace = [Management.Automation.Runspaces.RunspaceFactory]::CreateRunspace()
|
||||
$runspace.ApartmentState = "STA"
|
||||
$runspace.ThreadOptions = "ReuseThread"
|
||||
$runspace.Open()
|
||||
$runspace.SessionStateProxy.SetVariable("sync", $sync)
|
||||
$runspace.SessionStateProxy.SetVariable("workDir", $workDir)
|
||||
|
||||
$script = [Management.Automation.PowerShell]::Create()
|
||||
$script.Runspace = $runspace
|
||||
$script.AddScript({
|
||||
|
||||
function Log($msg) {
|
||||
$ts = (Get-Date).ToString("HH:mm:ss")
|
||||
$sync["WPFWin11ISOStatusLog"].Dispatcher.Invoke([action]{
|
||||
$sync["WPFWin11ISOStatusLog"].Text += "`n[$ts] $msg"
|
||||
$sync["WPFWin11ISOStatusLog"].CaretIndex = $sync["WPFWin11ISOStatusLog"].Text.Length
|
||||
$sync["WPFWin11ISOStatusLog"].ScrollToEnd()
|
||||
})
|
||||
Add-Content -Path (Join-Path $workDir "WinUtil_Win11ISO.log") -Value "[$ts] $msg" -ErrorAction SilentlyContinue
|
||||
}
|
||||
function SetProgress($label, $pct) {
|
||||
$sync["WPFWin11ISOStatusLog"].Dispatcher.Invoke([action]{
|
||||
$sync.progressBarTextBlock.Text = $label
|
||||
$sync.progressBarTextBlock.ToolTip = $label
|
||||
$sync.ProgressBar.Value = [Math]::Max($pct, 5)
|
||||
})
|
||||
}
|
||||
|
||||
try {
|
||||
if ($workDir -and (Test-Path $workDir)) {
|
||||
Log "Scanning files to delete in: $workDir"
|
||||
SetProgress "Scanning files..." 5
|
||||
|
||||
$allItems = @(Get-ChildItem -Path $workDir -Recurse -Force -ErrorAction SilentlyContinue)
|
||||
$total = $allItems.Count
|
||||
$deleted = 0
|
||||
|
||||
Log "Found $total items to delete."
|
||||
|
||||
# Delete files first, then directories (deepest first)
|
||||
$files = $allItems | Where-Object { -not $_.PSIsContainer }
|
||||
$dirs = $allItems | Where-Object { $_.PSIsContainer } |
|
||||
Sort-Object { $_.FullName.Length } -Descending
|
||||
|
||||
foreach ($f in $files) {
|
||||
try { Remove-Item -Path $f.FullName -Force -ErrorAction Stop } catch {}
|
||||
$deleted++
|
||||
if ($deleted % 100 -eq 0 -or $deleted -eq $files.Count) {
|
||||
$pct = [math]::Round(($deleted / [Math]::Max($total,1)) * 85) + 5
|
||||
SetProgress "Deleting files... ($deleted / $total)" $pct
|
||||
Log "Deleting files... $deleted of $total"
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($d in $dirs) {
|
||||
try { Remove-Item -Path $d.FullName -Force -Recurse -ErrorAction Stop } catch {}
|
||||
$deleted++
|
||||
if ($deleted % 50 -eq 0 -or $deleted -eq $total) {
|
||||
$pct = [math]::Round(($deleted / [Math]::Max($total,1)) * 85) + 5
|
||||
SetProgress "Removing directories... ($deleted / $total)" $pct
|
||||
Log "Removing directories... $deleted of $total"
|
||||
}
|
||||
}
|
||||
|
||||
# Remove the root work directory itself
|
||||
try { Remove-Item -Path $workDir -Force -Recurse -ErrorAction Stop } catch {}
|
||||
|
||||
if (Test-Path $workDir) {
|
||||
Log "WARNING: some items could not be deleted in $workDir"
|
||||
} else {
|
||||
Log "Temp directory deleted successfully."
|
||||
}
|
||||
} else {
|
||||
Log "No temp directory found — resetting UI."
|
||||
}
|
||||
|
||||
SetProgress "Resetting UI..." 95
|
||||
Log "Resetting interface..."
|
||||
|
||||
# ── Full UI reset on the dispatcher thread ──────────────────────
|
||||
$sync["WPFWin11ISOStatusLog"].Dispatcher.Invoke([action]{
|
||||
# Clear stored state
|
||||
$sync["Win11ISOWorkDir"] = $null
|
||||
$sync["Win11ISOContentsDir"] = $null
|
||||
$sync["Win11ISOImagePath"] = $null
|
||||
$sync["Win11ISODriveLetter"] = $null
|
||||
$sync["Win11ISOWimPath"] = $null
|
||||
$sync["Win11ISOImageInfo"] = $null
|
||||
$sync["Win11ISOUSBDisks"] = $null
|
||||
|
||||
# Reset UI elements
|
||||
$sync["WPFWin11ISOPath"].Text = "No ISO selected..."
|
||||
$sync["WPFWin11ISOFileInfo"].Visibility = "Collapsed"
|
||||
$sync["WPFWin11ISOVerifyResultPanel"].Visibility = "Collapsed"
|
||||
$sync["WPFWin11ISOOptionUSB"].Visibility = "Collapsed"
|
||||
$sync["WPFWin11ISOOutputSection"].Visibility = "Collapsed"
|
||||
$sync["WPFWin11ISOModifySection"].Visibility = "Collapsed"
|
||||
$sync["WPFWin11ISOMountSection"].Visibility = "Collapsed"
|
||||
$sync["WPFWin11ISOSelectSection"].Visibility = "Visible"
|
||||
$sync["WPFWin11ISOModifyButton"].IsEnabled = $true
|
||||
$sync["WPFWin11ISOCleanResetButton"].IsEnabled = $true
|
||||
|
||||
$sync.progressBarTextBlock.Text = ""
|
||||
$sync.progressBarTextBlock.ToolTip = ""
|
||||
$sync.ProgressBar.Value = 0
|
||||
|
||||
$sync["WPFWin11ISOStatusLog"].Height = 140
|
||||
$sync["WPFWin11ISOStatusLog"].Text = "Ready. Please select a Windows 11 ISO to begin."
|
||||
})
|
||||
}
|
||||
catch {
|
||||
Log "ERROR during Clean & Reset: $_"
|
||||
$sync["WPFWin11ISOStatusLog"].Dispatcher.Invoke([action]{
|
||||
$sync.progressBarTextBlock.Text = ""
|
||||
$sync.progressBarTextBlock.ToolTip = ""
|
||||
$sync.ProgressBar.Value = 0
|
||||
$sync["WPFWin11ISOCleanResetButton"].IsEnabled = $true
|
||||
})
|
||||
}
|
||||
}) | Out-Null
|
||||
|
||||
$script.BeginInvoke() | Out-Null
|
||||
}
|
||||
|
||||
function Invoke-WinUtilISOExport {
|
||||
|
||||
@@ -4,30 +4,14 @@ function Invoke-WinUtilISOScript {
|
||||
Applies WinUtil modifications to a mounted Windows 11 install.wim image.
|
||||
|
||||
.DESCRIPTION
|
||||
Performs the following operations against an already-mounted WIM image:
|
||||
|
||||
1. Removes provisioned AppX bloatware packages via DISM.
|
||||
2. Removes OneDriveSetup.exe from the system image.
|
||||
3. Loads offline registry hives (COMPONENTS, DEFAULT, NTUSER, SOFTWARE, SYSTEM)
|
||||
and applies the following tweaks:
|
||||
- Bypasses hardware requirement checks (CPU, RAM, SecureBoot, Storage, TPM).
|
||||
- Disables sponsored-app delivery and ContentDeliveryManager features.
|
||||
- Enables local-account OOBE path (BypassNRO).
|
||||
- Writes autounattend.xml to the Sysprep directory inside the WIM and,
|
||||
optionally, to the ISO/USB root so Windows Setup picks it up at boot.
|
||||
- Disables reserved storage.
|
||||
- Disables BitLocker device encryption.
|
||||
- Hides the Chat (Teams) taskbar icon.
|
||||
- Disables OneDrive folder backup (KFM).
|
||||
- Disables telemetry, advertising ID, and input personalization.
|
||||
- Blocks post-install delivery of DevHome, Outlook, and Teams.
|
||||
- Disables Windows Copilot.
|
||||
- Disables Windows Update during OOBE.
|
||||
4. Deletes unwanted scheduled-task XML definition files (CEIP, Appraiser, etc.).
|
||||
5. Removes the support\ folder from the ISO contents directory (if supplied).
|
||||
|
||||
Mounting and dismounting the WIM is the responsibility of the caller
|
||||
(e.g. Invoke-WinUtilISO).
|
||||
Removes AppX bloatware and OneDrive, injects hardware drivers (NVMe, Precision
|
||||
Touchpad/HID, and network) exported from the running system, optionally injects
|
||||
extended Storage & Network drivers from the ChrisTitusTech/storage-lan-drivers
|
||||
repository (requires git, installed via winget if absent), applies offline registry
|
||||
tweaks (hardware bypass, privacy, OOBE, telemetry, update suppression), deletes
|
||||
CEIP/WU scheduled-task definition files, and optionally drops autounattend.xml and
|
||||
removes the support\ folder from the ISO contents directory.
|
||||
Mounting/dismounting the WIM is the caller's responsibility (e.g. Invoke-WinUtilISO).
|
||||
|
||||
.PARAMETER ScratchDir
|
||||
Mandatory. Full path to the directory where the Windows image is currently mounted.
|
||||
@@ -62,15 +46,11 @@ function Invoke-WinUtilISOScript {
|
||||
.NOTES
|
||||
Author : Chris Titus @christitustech
|
||||
GitHub : https://github.com/ChrisTitusTech
|
||||
Version : 26.02.22
|
||||
Version : 26.02.25b
|
||||
#>
|
||||
param (
|
||||
[Parameter(Mandatory)][string]$ScratchDir,
|
||||
# Root directory of the extracted ISO contents. When supplied, autounattend.xml
|
||||
# is written here so Windows Setup picks it up automatically at boot.
|
||||
[string]$ISOContentsDir = "",
|
||||
# Autounattend XML content. In compiled winutil.ps1 this comes from the embedded
|
||||
# $WinUtilAutounattendXml here-string; in dev mode it is read from tools\autounattend.xml.
|
||||
[string]$AutoUnattendXml = "",
|
||||
[scriptblock]$Log = { param($m) Write-Output $m }
|
||||
)
|
||||
@@ -100,6 +80,69 @@ function Invoke-WinUtilISOScript {
|
||||
}
|
||||
}
|
||||
|
||||
# Copies driver package folders (one per exported .inf) whose online class
|
||||
# matches any of the supplied class names into a new temp staging directory.
|
||||
# Returns the staging directory path — caller must delete it when done.
|
||||
# Using a staging dir lets DISM inject all drivers in a single /Recurse
|
||||
# call instead of one DISM process launch per .inf file.
|
||||
function New-DriverStagingDir {
|
||||
param ([string]$ExportRoot, [string[]]$Classes)
|
||||
$stagingDir = Join-Path $env:TEMP "WinUtil_DriverStage_$(Get-Random)"
|
||||
New-Item -Path $stagingDir -ItemType Directory -Force | Out-Null
|
||||
Get-WindowsDriver -Online |
|
||||
Where-Object { $_.ClassName -in $Classes } |
|
||||
ForEach-Object { [IO.Path]::GetFileNameWithoutExtension($_.OriginalFileName) } |
|
||||
Select-Object -Unique |
|
||||
ForEach-Object {
|
||||
Get-ChildItem -Path $ExportRoot -Filter "$_.inf" -Recurse -ErrorAction SilentlyContinue |
|
||||
Select-Object -ExpandProperty DirectoryName -Unique |
|
||||
ForEach-Object {
|
||||
# Each exported driver lives in its own sub-folder;
|
||||
# copy that folder (with its binary files) into staging.
|
||||
$dest = Join-Path $stagingDir (Split-Path $_ -Leaf)
|
||||
Copy-Item -Path $_ -Destination $dest -Recurse -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
}
|
||||
return $stagingDir
|
||||
}
|
||||
|
||||
# Injects all drivers from $DriverDir into a DISM-mounted image in one call.
|
||||
function Add-DriversToImage {
|
||||
param (
|
||||
[string]$MountPath,
|
||||
[string]$DriverDir,
|
||||
[string]$Label = "image",
|
||||
[scriptblock]$Logger
|
||||
)
|
||||
& dism /English "/image:$MountPath" /Add-Driver "/Driver:$DriverDir" /Recurse 2>&1 |
|
||||
ForEach-Object { & $Logger " dism[$Label]: $_" }
|
||||
}
|
||||
|
||||
# Mounts boot.wim index 2, injects all drivers from $DriverDir, saves, dismounts.
|
||||
function Invoke-BootWimInject {
|
||||
param (
|
||||
[string]$BootWimPath,
|
||||
[string]$DriverDir,
|
||||
[scriptblock]$Logger
|
||||
)
|
||||
Set-ItemProperty -Path $BootWimPath -Name IsReadOnly -Value $false -ErrorAction SilentlyContinue
|
||||
$mountDir = Join-Path $env:TEMP "WinUtil_BootMount_$(Get-Random)"
|
||||
New-Item -Path $mountDir -ItemType Directory -Force | Out-Null
|
||||
try {
|
||||
& $Logger "Mounting boot.wim (index 2 — Windows Setup) for driver injection..."
|
||||
Mount-WindowsImage -ImagePath $BootWimPath -Index 2 -Path $mountDir -ErrorAction Stop | Out-Null
|
||||
Add-DriversToImage -MountPath $mountDir -DriverDir $DriverDir -Label "boot" -Logger $Logger
|
||||
& $Logger "Saving boot.wim..."
|
||||
Dismount-WindowsImage -Path $mountDir -Save -ErrorAction Stop | Out-Null
|
||||
& $Logger "boot.wim driver injection complete."
|
||||
} catch {
|
||||
& $Logger "Warning: boot.wim driver injection failed: $_"
|
||||
try { Dismount-WindowsImage -Path $mountDir -Discard -ErrorAction SilentlyContinue | Out-Null } catch {}
|
||||
} finally {
|
||||
Remove-Item -Path $mountDir -Recurse -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
}
|
||||
|
||||
# ═════════════════════════════════════════════════════════════════════════
|
||||
# 1. Remove provisioned AppX packages
|
||||
# ═════════════════════════════════════════════════════════════════════════
|
||||
@@ -164,7 +207,108 @@ function Invoke-WinUtilISOScript {
|
||||
}
|
||||
|
||||
# ═════════════════════════════════════════════════════════════════════════
|
||||
# 2. Remove OneDrive
|
||||
# 2. Inject hardware drivers (NVMe / Trackpad / Network)
|
||||
# Injected into BOTH install.wim (OS) AND boot.wim index 2 (Setup).
|
||||
# Without storage drivers in boot.wim, Windows Setup cannot see the
|
||||
# target disk on systems with unsupported NVMe / SATA controllers.
|
||||
# ═════════════════════════════════════════════════════════════════════════
|
||||
& $Log "Exporting hardware drivers from running system (NVMe, HID/Trackpad, Network)..."
|
||||
|
||||
$driverExportRoot = Join-Path $env:TEMP "WinUtil_DriverExport_$(Get-Random)"
|
||||
New-Item -Path $driverExportRoot -ItemType Directory -Force | Out-Null
|
||||
|
||||
try {
|
||||
Export-WindowsDriver -Online -Destination $driverExportRoot | Out-Null
|
||||
|
||||
# Stage matching driver folders then do a single DISM /Recurse call.
|
||||
# install.wim: SCSIAdapter + HIDClass + Net
|
||||
$installStage = New-DriverStagingDir -ExportRoot $driverExportRoot -Classes @('SCSIAdapter','HIDClass','Net')
|
||||
& $Log "Injecting staged drivers into install.wim (single DISM call)..."
|
||||
Add-DriversToImage -MountPath $ScratchDir -DriverDir $installStage -Label "install" -Logger $Log
|
||||
Remove-Item -Path $installStage -Recurse -Force -ErrorAction SilentlyContinue
|
||||
& $Log "install.wim driver injection complete."
|
||||
|
||||
# boot.wim: SCSIAdapter + Net only (HID not needed in WinPE)
|
||||
if ($ISOContentsDir -and (Test-Path $ISOContentsDir)) {
|
||||
$bootWim = Join-Path $ISOContentsDir "sources\boot.wim"
|
||||
if (Test-Path $bootWim) {
|
||||
$bootStage = New-DriverStagingDir -ExportRoot $driverExportRoot -Classes @('SCSIAdapter','Net')
|
||||
& $Log "Injecting staged drivers into boot.wim (single DISM call)..."
|
||||
Invoke-BootWimInject -BootWimPath $bootWim -DriverDir $bootStage -Logger $Log
|
||||
Remove-Item -Path $bootStage -Recurse -Force -ErrorAction SilentlyContinue
|
||||
} else {
|
||||
& $Log "Warning: boot.wim not found — skipping boot.wim driver injection."
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
& $Log "Error during driver export/injection: $_"
|
||||
} finally {
|
||||
Remove-Item -Path $driverExportRoot -Recurse -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
# ── 2c. Optional: extended Storage & Network drivers from community repo ──
|
||||
$extDriverChoice = [System.Windows.MessageBox]::Show(
|
||||
"Would you like to add extended Storage and Network drivers?`n`n" +
|
||||
"This installs EVERY Storage and Networking device driver " +
|
||||
"in EXISTANCE into the image. (~1000 drivers)`n`n" +
|
||||
"No Wireless drivers only Ethernet, use for stubborn systems " +
|
||||
"with unsupported NVMe or Ethernet controllers.",
|
||||
"Extended Drivers", "YesNo", "Question")
|
||||
|
||||
if ($extDriverChoice -eq 'Yes') {
|
||||
& $Log "Extended driver injection requested."
|
||||
|
||||
# Ensure git is available
|
||||
$gitCmd = Get-Command git -ErrorAction SilentlyContinue
|
||||
if (-not $gitCmd) {
|
||||
& $Log "Git not found — installing via winget..."
|
||||
winget install --id Git.Git -e --source winget `
|
||||
--accept-package-agreements --accept-source-agreements | Out-Null
|
||||
# Refresh PATH so git is visible in this session
|
||||
$env:PATH = [System.Environment]::GetEnvironmentVariable('PATH', 'Machine') + ';' +
|
||||
[System.Environment]::GetEnvironmentVariable('PATH', 'User')
|
||||
$gitCmd = Get-Command git -ErrorAction SilentlyContinue
|
||||
}
|
||||
|
||||
if (-not $gitCmd) {
|
||||
& $Log "Warning: git could not be found after install attempt — skipping extended drivers."
|
||||
} else {
|
||||
$extRepoDir = Join-Path $env:TEMP "WinUtil_ExtDrivers_$(Get-Random)"
|
||||
try {
|
||||
& $Log "Cloning storage-lan-drivers repository..."
|
||||
& git clone --depth 1 `
|
||||
"https://github.com/ChrisTitusTech/storage-lan-drivers" `
|
||||
$extRepoDir 2>&1 | ForEach-Object { & $Log " git: $_" }
|
||||
|
||||
if (Test-Path $extRepoDir) {
|
||||
& $Log "Injecting extended drivers into install.wim (this may take several minutes)..."
|
||||
Add-DriversToImage -MountPath $ScratchDir -DriverDir $extRepoDir -Label "install" -Logger $Log
|
||||
& $Log "Extended driver injection into install.wim complete."
|
||||
|
||||
if ($ISOContentsDir -and (Test-Path $ISOContentsDir)) {
|
||||
$bootWimExt = Join-Path $ISOContentsDir "sources\boot.wim"
|
||||
if (Test-Path $bootWimExt) {
|
||||
& $Log "Injecting extended drivers into boot.wim..."
|
||||
Invoke-BootWimInject -BootWimPath $bootWimExt -DriverDir $extRepoDir -Logger $Log
|
||||
} else {
|
||||
& $Log "Warning: boot.wim not found — skipping extended driver injection into boot.wim."
|
||||
}
|
||||
}
|
||||
} else {
|
||||
& $Log "Warning: repository clone directory not found — skipping extended drivers."
|
||||
}
|
||||
} catch {
|
||||
& $Log "Error during extended driver injection: $_"
|
||||
} finally {
|
||||
Remove-Item -Path $extRepoDir -Recurse -Force -ErrorAction SilentlyContinue
|
||||
}
|
||||
}
|
||||
} else {
|
||||
& $Log "Extended driver injection skipped."
|
||||
}
|
||||
|
||||
# ═════════════════════════════════════════════════════════════════════════
|
||||
# 3. Remove OneDrive
|
||||
# ═════════════════════════════════════════════════════════════════════════
|
||||
& $Log "Removing OneDrive..."
|
||||
& takeown /f "$ScratchDir\Windows\System32\OneDriveSetup.exe" | Out-Null
|
||||
@@ -172,7 +316,7 @@ function Invoke-WinUtilISOScript {
|
||||
Remove-Item -Path "$ScratchDir\Windows\System32\OneDriveSetup.exe" -Force -ErrorAction SilentlyContinue
|
||||
|
||||
# ═════════════════════════════════════════════════════════════════════════
|
||||
# 3. Registry tweaks
|
||||
# 4. Registry tweaks
|
||||
# ═════════════════════════════════════════════════════════════════════════
|
||||
& $Log "Loading offline registry hives..."
|
||||
reg load HKLM\zCOMPONENTS "$ScratchDir\Windows\System32\config\COMPONENTS"
|
||||
@@ -305,7 +449,7 @@ function Invoke-WinUtilISOScript {
|
||||
reg unload HKLM\zSYSTEM
|
||||
|
||||
# ═════════════════════════════════════════════════════════════════════════
|
||||
# 4. Delete scheduled task definition files
|
||||
# 5. Delete scheduled task definition files
|
||||
# ═════════════════════════════════════════════════════════════════════════
|
||||
& $Log "Deleting scheduled task definition files..."
|
||||
$tasksPath = "$ScratchDir\Windows\System32\Tasks"
|
||||
@@ -325,7 +469,7 @@ function Invoke-WinUtilISOScript {
|
||||
& $Log "Scheduled task files deleted."
|
||||
|
||||
# ═════════════════════════════════════════════════════════════════════════
|
||||
# 5. Remove ISO support folder (fresh-install only; not needed)
|
||||
# 6. Remove ISO support folder (fresh-install only; not needed)
|
||||
# ═════════════════════════════════════════════════════════════════════════
|
||||
if ($ISOContentsDir -and (Test-Path $ISOContentsDir)) {
|
||||
& $Log "Removing ISO support\ folder..."
|
||||
|
||||
@@ -17,7 +17,7 @@ function Invoke-WinUtilISORefreshUSBDrives {
|
||||
|
||||
foreach ($disk in $removable) {
|
||||
$sizeGB = [math]::Round($disk.Size / 1GB, 1)
|
||||
$label = "Disk $($disk.Number): $($disk.FriendlyName) [$sizeGB GB] — $($disk.PartitionStyle)"
|
||||
$label = "Disk $($disk.Number): $($disk.FriendlyName) [$sizeGB GB] - $($disk.PartitionStyle)"
|
||||
$combo.Items.Add($label)
|
||||
}
|
||||
$combo.SelectedIndex = 0
|
||||
@@ -38,7 +38,7 @@ function Invoke-WinUtilISOWriteUSB {
|
||||
|
||||
if (-not $contentsDir -or -not (Test-Path $contentsDir)) {
|
||||
[System.Windows.MessageBox]::Show(
|
||||
"No modified ISO content found. Please complete Steps 1–3 first.",
|
||||
"No modified ISO content found. Please complete Steps 1-3 first.",
|
||||
"Not Ready", "OK", "Warning")
|
||||
return
|
||||
}
|
||||
@@ -107,28 +107,56 @@ function Invoke-WinUtilISOWriteUSB {
|
||||
return $null
|
||||
}
|
||||
|
||||
# ── Diskpart script: clean + GPT + format only (no assign) ──────────
|
||||
# We intentionally omit "assign" here and let PowerShell assign letters
|
||||
# explicitly below. diskpart's "assign" can silently fail on drives that
|
||||
# previously had letter bindings still present in the registry, which is
|
||||
# the root cause of the "could not locate partition" error.
|
||||
$dpScript = @"
|
||||
# ── Phase 1: Clean the disk via diskpart ────────────────────────────
|
||||
# Only run "clean" here. "convert gpt" in diskpart requires the disk to
|
||||
# already be MBR; after a clean the disk is RAW, so convert gpt fails on
|
||||
# many systems. We use Initialize-Disk (which accepts RAW disks) instead.
|
||||
$dpScript1 = @"
|
||||
select disk $diskNum
|
||||
clean
|
||||
convert gpt
|
||||
create partition efi size=512
|
||||
format quick fs=fat32 label="SYSTEM"
|
||||
create partition primary
|
||||
format quick fs=fat32 label="WINPE"
|
||||
exit
|
||||
"@
|
||||
$dpFile = Join-Path $env:TEMP "winutil_diskpart_$(Get-Random).txt"
|
||||
$dpScript | Set-Content -Path $dpFile -Encoding ASCII
|
||||
Log "Running diskpart on Disk $diskNum..."
|
||||
$dpOut = diskpart /s $dpFile 2>&1
|
||||
Remove-Item $dpFile -Force -ErrorAction SilentlyContinue
|
||||
# Log diskpart output for diagnostics
|
||||
$dpOut | Where-Object { $_ -match '\S' } | ForEach-Object { Log " diskpart: $_" }
|
||||
$dpFile1 = Join-Path $env:TEMP "winutil_diskpart_$(Get-Random).txt"
|
||||
$dpScript1 | Set-Content -Path $dpFile1 -Encoding ASCII
|
||||
Log "Running diskpart clean on Disk $diskNum..."
|
||||
$dpOut1 = diskpart /s $dpFile1 2>&1
|
||||
Remove-Item $dpFile1 -Force -ErrorAction SilentlyContinue
|
||||
$dpOut1 | Where-Object { $_ -match '\S' } | ForEach-Object { Log " diskpart: $_" }
|
||||
|
||||
# ── Phase 2: Initialize as GPT via PowerShell ────────────────────────
|
||||
# After "clean", Windows may still see the disk as initialized (stale
|
||||
# metadata). Initialize-Disk only accepts RAW disks; Set-Disk handles
|
||||
# already-initialized (MBR/GPT) disks with no partitions. Try both.
|
||||
Start-Sleep -Seconds 2
|
||||
Update-Disk -Number $diskNum -ErrorAction SilentlyContinue
|
||||
$diskObj = Get-Disk -Number $diskNum -ErrorAction Stop
|
||||
if ($diskObj.PartitionStyle -eq 'RAW') {
|
||||
Initialize-Disk -Number $diskNum -PartitionStyle GPT -ErrorAction Stop
|
||||
Log "Disk $diskNum initialized as GPT."
|
||||
} else {
|
||||
Set-Disk -Number $diskNum -PartitionStyle GPT -ErrorAction Stop
|
||||
Log "Disk $diskNum converted to GPT (was $($diskObj.PartitionStyle))."
|
||||
}
|
||||
|
||||
# ── Phase 3: Create partitions via diskpart ──────────────────────────
|
||||
# "create partition efi" is not supported on removable media.
|
||||
# A single FAT32 primary partition is all that is needed for a UEFI-
|
||||
# bootable Windows install USB - the firmware locates \EFI\Boot\bootx64.efi
|
||||
# on any FAT32 volume regardless of GPT partition type.
|
||||
# FAT32 label limit is 11 chars; "W11-yyMMdd" = 10, fits without trimming.
|
||||
$volLabel = "W11-" + (Get-Date).ToString('yyMMdd')
|
||||
$dpScript2 = @"
|
||||
select disk $diskNum
|
||||
create partition primary
|
||||
format quick fs=fat32 label="$volLabel"
|
||||
exit
|
||||
"@
|
||||
$dpFile2 = Join-Path $env:TEMP "winutil_diskpart2_$(Get-Random).txt"
|
||||
$dpScript2 | Set-Content -Path $dpFile2 -Encoding ASCII
|
||||
Log "Creating partitions on Disk $diskNum..."
|
||||
$dpOut2 = diskpart /s $dpFile2 2>&1
|
||||
Remove-Item $dpFile2 -Force -ErrorAction SilentlyContinue
|
||||
$dpOut2 | Where-Object { $_ -match '\S' } | ForEach-Object { Log " diskpart: $_" }
|
||||
|
||||
SetProgress "Assigning drive letters..." 30
|
||||
Start-Sleep -Seconds 3 # allow Windows to settle after partition creation
|
||||
@@ -169,28 +197,29 @@ exit
|
||||
$wimSizeMB = [math]::Round((Get-Item $installWim).Length / 1MB)
|
||||
if ($wimSizeMB -gt 3800) {
|
||||
# FAT32 limit – split with DISM
|
||||
Log "install.wim is $wimSizeMB MB – splitting for FAT32 compatibility..."
|
||||
Log "install.wim is $wimSizeMB MB - splitting for FAT32 compatibility...This will take several minutes."
|
||||
$splitDest = Join-Path $usbDrive "sources\install.swm"
|
||||
New-Item -ItemType Directory -Path (Split-Path $splitDest) -Force | Out-Null
|
||||
Split-WindowsImage -ImagePath $installWim `
|
||||
-SplitImagePath $splitDest `
|
||||
-FileSize 3800 -CheckIntegrity | Out-Null
|
||||
-FileSize 3800 -CheckIntegrity
|
||||
Log "install.wim split complete."
|
||||
|
||||
# Copy everything else (exclude install.wim)
|
||||
Log "Copying remaining files to USB..."
|
||||
$robocopyArgs = @($contentsDir, $usbDrive, "/E", "/XF", "install.wim", "/NFL", "/NDL", "/NJH", "/NJS")
|
||||
& robocopy @robocopyArgs | Out-Null
|
||||
& robocopy @robocopyArgs
|
||||
} else {
|
||||
& robocopy $contentsDir $usbDrive /E /NFL /NDL /NJH /NJS | Out-Null
|
||||
& robocopy $contentsDir $usbDrive /E /NFL /NDL /NJH /NJS
|
||||
}
|
||||
} else {
|
||||
& robocopy $contentsDir $usbDrive /E /NFL /NDL /NJH /NJS | Out-Null
|
||||
& robocopy $contentsDir $usbDrive /E /NFL /NDL /NJH /NJS
|
||||
}
|
||||
|
||||
SetProgress "Finalising USB drive..." 90
|
||||
Log "Files copied to USB."
|
||||
|
||||
SetProgress "USB write complete ✔" 100
|
||||
SetProgress "USB write complete" 100
|
||||
Log "USB drive is ready for use."
|
||||
|
||||
$sync["WPFWin11ISOStatusLog"].Dispatcher.Invoke([action]{
|
||||
|
||||
@@ -534,9 +534,11 @@ $sync["FontScalingApplyButton"].Add_Click({
|
||||
|
||||
# ── Win11ISO Tab button handlers ──────────────────────────────────────────────
|
||||
|
||||
# Check for an existing working directory each time the Win11ISO tab is opened
|
||||
$sync["WPFTab5BT"].Add_Click({
|
||||
Invoke-WinUtilISOCheckExistingWork
|
||||
$sync["Form"].Dispatcher.BeginInvoke(
|
||||
[System.Windows.Threading.DispatcherPriority]::Background,
|
||||
[action]{ Invoke-WinUtilISOCheckExistingWork }
|
||||
) | Out-Null
|
||||
})
|
||||
|
||||
$sync["WPFWin11ISOBrowseButton"].Add_Click({
|
||||
|
||||
@@ -273,22 +273,46 @@
|
||||
<Style TargetType="ComboBox">
|
||||
<Setter Property="Foreground" Value="{DynamicResource ComboBoxForegroundColor}" />
|
||||
<Setter Property="Background" Value="{DynamicResource ComboBoxBackgroundColor}" />
|
||||
<Setter Property="MinWidth" Value="{DynamicResource ButtonWidth}" />
|
||||
<Setter Property="Template">
|
||||
<Setter.Value>
|
||||
<ControlTemplate TargetType="ComboBox">
|
||||
<Grid>
|
||||
<ToggleButton x:Name="ToggleButton"
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding Background}"
|
||||
BorderThickness="0"
|
||||
IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
|
||||
ClickMode="Press">
|
||||
<TextBlock Text="{TemplateBinding SelectionBoxItem}"
|
||||
Foreground="{TemplateBinding Foreground}"
|
||||
Background="Transparent"
|
||||
HorizontalAlignment="Center" VerticalAlignment="Center" Margin="2"
|
||||
/>
|
||||
</ToggleButton>
|
||||
<!-- Outer border gives the combo a visible box -->
|
||||
<Border x:Name="OuterBorder"
|
||||
BorderBrush="{DynamicResource BorderColor}"
|
||||
BorderThickness="1"
|
||||
CornerRadius="{DynamicResource ButtonCornerRadius}"
|
||||
Background="{TemplateBinding Background}">
|
||||
<ToggleButton x:Name="ToggleButton"
|
||||
Background="Transparent"
|
||||
BorderThickness="0"
|
||||
IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
|
||||
ClickMode="Press">
|
||||
<!-- Text + arrow laid out in a two-column Grid -->
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock Grid.Column="0"
|
||||
Text="{TemplateBinding SelectionBoxItem}"
|
||||
Foreground="{TemplateBinding Foreground}"
|
||||
Background="Transparent"
|
||||
HorizontalAlignment="Left" VerticalAlignment="Center"
|
||||
Margin="6,3,2,3"/>
|
||||
<!-- Scalable vector chevron -->
|
||||
<Path Grid.Column="1"
|
||||
Data="M 0,0 L 8,0 L 4,5 Z"
|
||||
Fill="{TemplateBinding Foreground}"
|
||||
Width="8" Height="5"
|
||||
VerticalAlignment="Center"
|
||||
HorizontalAlignment="Center"
|
||||
Stretch="Uniform"
|
||||
Margin="4,0,6,0"/>
|
||||
</Grid>
|
||||
</ToggleButton>
|
||||
</Border>
|
||||
<Popup x:Name="Popup"
|
||||
IsOpen="{TemplateBinding IsDropDownOpen}"
|
||||
Placement="Bottom"
|
||||
@@ -297,11 +321,11 @@
|
||||
PopupAnimation="Slide">
|
||||
<Border x:Name="DropDownBorder"
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding Foreground}"
|
||||
BorderBrush="{DynamicResource BorderColor}"
|
||||
BorderThickness="1"
|
||||
CornerRadius="4">
|
||||
<ScrollViewer>
|
||||
<ItemsPresenter HorizontalAlignment="Center" VerticalAlignment="Center" Margin="2"/>
|
||||
<ItemsPresenter HorizontalAlignment="Left" VerticalAlignment="Center" Margin="4,2"/>
|
||||
</ScrollViewer>
|
||||
</Border>
|
||||
</Popup>
|
||||
@@ -1353,8 +1377,7 @@
|
||||
<!-- ═══════════════════════════════════════════════════════════ -->
|
||||
<!-- STEP 1 : Select Windows 11 ISO -->
|
||||
<!-- ═══════════════════════════════════════════════════════════ -->
|
||||
<Border Grid.Row="0" Name="WPFWin11ISOSelectSection" Style="{StaticResource BorderStyle}">
|
||||
<Grid Margin="5">
|
||||
<Grid Grid.Row="0" Name="WPFWin11ISOSelectSection" Margin="5" HorizontalAlignment="Left" MinWidth="{DynamicResource ButtonWidth}">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
@@ -1440,17 +1463,16 @@
|
||||
Height="{DynamicResource ButtonHeight}"/>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</Grid>
|
||||
</Border>
|
||||
</Grid>
|
||||
|
||||
<!-- ═══════════════════════════════════════════════════════════ -->
|
||||
<!-- STEP 2 : Mount & Verify ISO -->
|
||||
<!-- ═══════════════════════════════════════════════════════════ -->
|
||||
<Border Grid.Row="1"
|
||||
Name="WPFWin11ISOMountSection"
|
||||
Style="{StaticResource BorderStyle}"
|
||||
Visibility="Collapsed">
|
||||
<Grid Margin="5">
|
||||
<Grid Grid.Row="1"
|
||||
Name="WPFWin11ISOMountSection"
|
||||
Margin="5"
|
||||
Visibility="Collapsed"
|
||||
HorizontalAlignment="Left" MinWidth="{DynamicResource ButtonWidth}">
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="Auto"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
@@ -1500,22 +1522,20 @@
|
||||
FontSize="{DynamicResource FontSize}"
|
||||
Foreground="{DynamicResource MainForegroundColor}"
|
||||
Background="{DynamicResource MainBackgroundColor}"
|
||||
BorderBrush="{DynamicResource BorderColor}"
|
||||
HorizontalAlignment="Stretch"
|
||||
HorizontalAlignment="Left"
|
||||
Margin="0,0,0,0"/>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</Grid>
|
||||
</Border>
|
||||
</Grid>
|
||||
|
||||
<!-- ═══════════════════════════════════════════════════════════ -->
|
||||
<!-- STEP 3 : Modify install.wim -->
|
||||
<!-- ═══════════════════════════════════════════════════════════ -->
|
||||
<Border Grid.Row="2"
|
||||
Name="WPFWin11ISOModifySection"
|
||||
Style="{StaticResource BorderStyle}"
|
||||
Visibility="Collapsed">
|
||||
<StackPanel Margin="5">
|
||||
<StackPanel Grid.Row="2"
|
||||
Name="WPFWin11ISOModifySection"
|
||||
Margin="5"
|
||||
Visibility="Collapsed"
|
||||
HorizontalAlignment="Left" MinWidth="{DynamicResource ButtonWidth}">
|
||||
<TextBlock FontSize="{DynamicResource FontSize}" FontWeight="Bold"
|
||||
Foreground="{DynamicResource MainForegroundColor}" Margin="0,0,0,8">
|
||||
Step 3 - Modify install.wim
|
||||
@@ -1533,17 +1553,16 @@
|
||||
HorizontalAlignment="Left"
|
||||
Width="Auto" Padding="12,0"
|
||||
Height="{DynamicResource ButtonHeight}"/>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
|
||||
<!-- ═══════════════════════════════════════════════════════════ -->
|
||||
<!-- STEP 4 : Output Options -->
|
||||
<!-- ═══════════════════════════════════════════════════════════ -->
|
||||
<Border Grid.Row="3"
|
||||
Name="WPFWin11ISOOutputSection"
|
||||
Style="{StaticResource BorderStyle}"
|
||||
Visibility="Collapsed">
|
||||
<StackPanel Margin="5">
|
||||
<StackPanel Grid.Row="3"
|
||||
Name="WPFWin11ISOOutputSection"
|
||||
Margin="5"
|
||||
Visibility="Collapsed"
|
||||
HorizontalAlignment="Left" MinWidth="{DynamicResource ButtonWidth}">
|
||||
<!-- Header row: title + Clean & Reset button -->
|
||||
<Grid Margin="0,0,0,12">
|
||||
<Grid.ColumnDefinitions>
|
||||
@@ -1628,14 +1647,12 @@
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
||||
</StackPanel>
|
||||
</Border>
|
||||
</StackPanel>
|
||||
|
||||
<!-- ═══════════════════════════════════════════════════════════ -->
|
||||
<!-- Status / Log Output -->
|
||||
<!-- ═══════════════════════════════════════════════════════════ -->
|
||||
<Border Grid.Row="4" Style="{StaticResource BorderStyle}">
|
||||
<StackPanel>
|
||||
<StackPanel Grid.Row="4" Margin="5">
|
||||
<TextBlock FontSize="{DynamicResource FontSize}" FontWeight="Bold"
|
||||
Foreground="{DynamicResource MainForegroundColor}" Margin="0,0,0,6">
|
||||
Status Log
|
||||
@@ -1651,7 +1668,6 @@
|
||||
BorderThickness="1"
|
||||
Text="Ready. Please select a Windows 11 ISO to begin."/>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
||||
</Grid>
|
||||
</ScrollViewer>
|
||||
|
||||
Reference in New Issue
Block a user