Skip to content

Commit 49cbe45

Browse files
committed
Rework ADK detection
1 parent 7dcb0d1 commit 49cbe45

3 files changed

Lines changed: 83 additions & 2 deletions

File tree

functions/microwin/Invoke-MicrowinGetIso.ps1

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,17 @@ function Invoke-MicrowinGetIso {
122122
Set-WinUtilTaskbaritem -state "Indeterminate" -overlay "logo"
123123
Invoke-MicrowinBusyInfo -action "wip" -message "Checking system requirements..." -interactive $false
124124

125+
$adkKitsRoot = Microwin-GetKitsRoot -wow64environment $false
126+
$adkKitsRoot_WOW64Environ = Microwin-GetKitsRoot -wow64environment $true
127+
128+
$expectedADKPath = "$($adkKitsRoot)Assessment and Deployment Kit"
129+
$expectedADKPath_WOW64Environ = "$($adkKitsRoot_WOW64Environ)Assessment and Deployment Kit"
130+
125131
$oscdimgPath = Join-Path $env:TEMP 'oscdimg.exe'
126-
$oscdImgFound = [bool] (Get-Command -ErrorAction Ignore -Type Application oscdimg.exe) -or (Test-Path $oscdimgPath -PathType Leaf)
132+
$oscdImgFound = [bool] (Microwin-TestKitsRootPaths -adkKitsRootPath "$expectedADKPath" -adkKitsRootPath_WOW64Environ "$expectedADKPath_WOW64Environ") -or (Test-Path $oscdimgPath -PathType Leaf)
127133
Write-Host "oscdimg.exe on system: $oscdImgFound"
128134

129-
if (!$oscdImgFound) {
135+
if (-not ($oscdImgFound)) {
130136
$downloadFromGitHub = $sync.WPFMicrowinDownloadFromGitHub.IsChecked
131137

132138
if (!$downloadFromGitHub) {
@@ -162,6 +168,30 @@ function Invoke-MicrowinGetIso {
162168
Write-Host "oscdimg.exe was successfully downloaded from github"
163169
}
164170
}
171+
} elseif (Microwin-TestKitsRootPaths -adkKitsRootPath "$expectedADKPath" -adkKitsRootPath_WOW64Environ "$expectedADKPath_WOW64Environ") {
172+
# We have to guess where oscdimg is. We'll check both values...
173+
$peToolsPath = ""
174+
175+
if ($expectedADKPath -ne "Assessment and Deployment Kit") { $peToolsPath = $expectedADKPath }
176+
if (($peToolsPath -eq "") -and ($expectedADKPath_WOW64Environ -ne "Assessment and Deployment Kit")) { $peToolsPath = $expectedADKPath_WOW64Environ }
177+
178+
Write-Host "Using $peToolsPath as the Preinstallation Environment tools path..."
179+
# Paths change depending on platform
180+
if ([Environment]::Is64BitOperatingSystem) {
181+
$oscdimgPath = "$peToolsPath\Deployment Tools\amd64\Oscdimg\oscdimg.exe"
182+
} else {
183+
$oscdimgPath = "$peToolsPath\Deployment Tools\x86\Oscdimg\oscdimg.exe"
184+
}
185+
186+
# If it's a non-existent file, we won't continue.
187+
if (-not (Test-Path -Path "$oscdimgPath" -PathType Leaf)) {
188+
$oscdimgFound = $false
189+
}
190+
}
191+
192+
if (-not ($oscdimgFound)) {
193+
[System.Windows.MessageBox]::Show("oscdimg.exe is not found on the system. Cannot continue.")
194+
return
165195
}
166196

167197
Invoke-MicrowinBusyInfo -action "wip" -message "Checking disk space..." -interactive $false
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
function Microwin-GetKitsRoot {
2+
<#
3+
.SYNOPSIS
4+
Gets the kits root path for the Windows Assessment and Deployment Kit (ADK)
5+
.PARAMETER wow64environment
6+
Determines whether to search in a WOW64 compatibility environment (HKLM\SOFTWARE\WOW6432Node)
7+
.OUTPUTS
8+
The path to the kits root
9+
#>
10+
11+
param (
12+
[Parameter(Mandatory = $true, Position = 0)] [bool]$wow64environment
13+
)
14+
15+
$adk10KitsRoot = ""
16+
17+
# if we set the wow64 bit on and we're on a 32-bit system, then we prematurely return the value
18+
if (($wow64environment -eq $true) -and (-not [Environment]::Is64BitOperatingSystem)) {
19+
return $adk10KitsRoot
20+
}
21+
22+
$regPath = ""
23+
if ($wow64environment) {
24+
$regPath = "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows Kits\Installed Roots"
25+
} else {
26+
$regPath = "HKLM:\SOFTWARE\Microsoft\Windows Kits\Installed Roots"
27+
}
28+
29+
if ((Test-Path "$regPath") -eq $false) {
30+
return $adk10KitsRoot
31+
}
32+
33+
try {
34+
$adk10KitsRoot = Get-ItemPropertyValue -Path $regPath -Name "KitsRoot10" -ErrorAction Stop
35+
} catch {
36+
Write-Host "Could not find ADK."
37+
}
38+
39+
return $adk10KitsRoot
40+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
function Microwin-TestKitsRootPaths {
2+
param (
3+
[Parameter(Mandatory = $true, Position = 0)] [string]$adkKitsRootPath,
4+
[Parameter(Mandatory = $true, Position = 1)] [string]$adkKitsRootPath_WOW64Environ
5+
)
6+
7+
if (Test-Path "$adkKitsRootPath") { return $true }
8+
if (Test-Path "$adkKitsRootPath_WOW64Environ") { return $true }
9+
10+
return $false
11+
}

0 commit comments

Comments
 (0)