mirror of
https://github.com/rbalsleyMSFT/FFU.git
synced 2026-06-14 02:09:35 -06:00
Updates ADK detection to use executable paths
Improves the reliability of locating Windows ADK and WinPE add-on installations. Updates registry searches to locate installer executables in the bundle cache path instead of relying on display names, avoiding potential mismatches. Expands the registry queries to check both the WOW6432Node and standard uninstall paths to better support different installation contexts. Validates the Windows Deployment Tools feature by verifying the existence of expected script files rather than checking the registry.
This commit is contained in:
@@ -1722,40 +1722,58 @@ function Install-ADK {
|
||||
}
|
||||
function Get-InstalledProgramRegKey {
|
||||
param (
|
||||
[string]$DisplayName
|
||||
[ValidateSet("Windows ADK", "WinPE add-on")]
|
||||
[string]$ADKOption
|
||||
)
|
||||
|
||||
$uninstallRegPath = "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
|
||||
$uninstallRegKeys = Get-ChildItem -Path $uninstallRegPath -Recurse
|
||||
# Match ADK entries using installer executable names in BundleCachePath
|
||||
$bundleExecutableName = switch ($ADKOption) {
|
||||
"Windows ADK" { "adksetup.exe" }
|
||||
"WinPE add-on" { "adkwinpesetup.exe" }
|
||||
}
|
||||
|
||||
# Check both uninstall roots to support different install contexts
|
||||
$uninstallRegPaths = @(
|
||||
"HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall",
|
||||
"HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"
|
||||
)
|
||||
|
||||
foreach ($uninstallRegPath in $uninstallRegPaths) {
|
||||
if (-not (Test-Path -Path $uninstallRegPath)) {
|
||||
continue
|
||||
}
|
||||
|
||||
$uninstallRegKeys = Get-ChildItem -Path $uninstallRegPath -Recurse -ErrorAction SilentlyContinue
|
||||
|
||||
foreach ($regKey in $uninstallRegKeys) {
|
||||
try {
|
||||
$regValue = $regKey.GetValue("DisplayName")
|
||||
if ($regValue -eq $DisplayName) {
|
||||
$bundleCachePath = $regKey.GetValue("BundleCachePath")
|
||||
if ($null -ne $bundleCachePath) {
|
||||
$bundleFileName = Split-Path -Path $bundleCachePath -Leaf
|
||||
if ($bundleFileName -ieq $bundleExecutableName) {
|
||||
return $regKey
|
||||
}
|
||||
}
|
||||
}
|
||||
catch {
|
||||
WriteLog $_
|
||||
throw "Error retrieving installed program info for $DisplayName : $_"
|
||||
throw "Error retrieving installed program info for $ADKOption : $_"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $null
|
||||
}
|
||||
|
||||
function Uninstall-ADK {
|
||||
param (
|
||||
[ValidateSet("Windows ADK", "WinPE add-on")]
|
||||
[string]$ADKOption
|
||||
)
|
||||
|
||||
# Match name as it appears in the registry
|
||||
$displayName = switch ($ADKOption) {
|
||||
"Windows ADK" { "Windows Assessment and Deployment Kit" }
|
||||
"WinPE add-on" { "Windows Assessment and Deployment Kit Windows Preinstallation Environment Add-ons" }
|
||||
}
|
||||
|
||||
try {
|
||||
$adkRegKey = Get-InstalledProgramRegKey -DisplayName $displayName
|
||||
# Find ADK entry by bundle executable path instead of display name
|
||||
$adkRegKey = Get-InstalledProgramRegKey -ADKOption $ADKOption
|
||||
|
||||
if (-not $adkRegKey) {
|
||||
WriteLog "$ADKOption is not installed."
|
||||
@@ -1780,13 +1798,9 @@ function Confirm-ADKVersionIsLatest {
|
||||
[string]$ADKOption
|
||||
)
|
||||
|
||||
$displayName = switch ($ADKOption) {
|
||||
"Windows ADK" { "Windows Assessment and Deployment Kit" }
|
||||
"WinPE add-on" { "Windows Assessment and Deployment Kit Windows Preinstallation Environment Add-ons" }
|
||||
}
|
||||
|
||||
try {
|
||||
$adkRegKey = Get-InstalledProgramRegKey -DisplayName $displayName
|
||||
# Find ADK entry by bundle executable path instead of display name
|
||||
$adkRegKey = Get-InstalledProgramRegKey -ADKOption $ADKOption
|
||||
|
||||
if (-not $adkRegKey) {
|
||||
return $false
|
||||
@@ -1860,12 +1874,17 @@ function Get-ADK {
|
||||
throw "Windows ADK installation path could not be found."
|
||||
}
|
||||
|
||||
# If ADK was already installed, then check if the Windows Deployment Tools feature is also installed
|
||||
$deploymentToolsRegKey = Get-InstalledProgramRegKey -DisplayName "Windows Deployment Tools"
|
||||
# If ADK is installed, validate Deployment Tools by checking DandISetEnv.bat
|
||||
$deploymentToolsEnvPath = Join-Path $adkPath "Assessment and Deployment Kit\Deployment Tools\DandISetEnv.bat"
|
||||
|
||||
if (-not $deploymentToolsRegKey) {
|
||||
if (-not (Test-Path -Path $deploymentToolsEnvPath)) {
|
||||
WriteLog "ADK is installed, but the Windows Deployment Tools feature is not installed."
|
||||
$adkRegKey = Get-InstalledProgramRegKey -DisplayName "Windows Assessment and Deployment Kit"
|
||||
$adkRegKey = Get-InstalledProgramRegKey -ADKOption "Windows ADK"
|
||||
|
||||
if ($null -eq $adkRegKey) {
|
||||
throw "Failed to locate the installed ADK package to install Windows Deployment Tools."
|
||||
}
|
||||
|
||||
$adkBundleCachePath = $adkRegKey.GetValue("BundleCachePath")
|
||||
if ($adkBundleCachePath) {
|
||||
WriteLog "Installing Windows Deployment Tools..."
|
||||
|
||||
Reference in New Issue
Block a user