diff --git a/functions/microwin/Invoke-MicrowinGetIso.ps1 b/functions/microwin/Invoke-MicrowinGetIso.ps1 index c8fe8ae2..9ad05e1a 100644 --- a/functions/microwin/Invoke-MicrowinGetIso.ps1 +++ b/functions/microwin/Invoke-MicrowinGetIso.ps1 @@ -122,11 +122,17 @@ function Invoke-MicrowinGetIso { Set-WinUtilTaskbaritem -state "Indeterminate" -overlay "logo" Invoke-MicrowinBusyInfo -action "wip" -message "Checking system requirements..." -interactive $false + $adkKitsRoot = Microwin-GetKitsRoot -wow64environment $false + $adkKitsRoot_WOW64Environ = Microwin-GetKitsRoot -wow64environment $true + + $expectedADKPath = "$($adkKitsRoot)Assessment and Deployment Kit" + $expectedADKPath_WOW64Environ = "$($adkKitsRoot_WOW64Environ)Assessment and Deployment Kit" + $oscdimgPath = Join-Path $env:TEMP 'oscdimg.exe' - $oscdImgFound = [bool] (Get-Command -ErrorAction Ignore -Type Application oscdimg.exe) -or (Test-Path $oscdimgPath -PathType Leaf) + $oscdImgFound = [bool] (Microwin-TestKitsRootPaths -adkKitsRootPath "$expectedADKPath" -adkKitsRootPath_WOW64Environ "$expectedADKPath_WOW64Environ") -or (Test-Path $oscdimgPath -PathType Leaf) Write-Host "oscdimg.exe on system: $oscdImgFound" - if (!$oscdImgFound) { + if (-not ($oscdImgFound)) { $downloadFromGitHub = $sync.WPFMicrowinDownloadFromGitHub.IsChecked if (!$downloadFromGitHub) { @@ -162,6 +168,30 @@ function Invoke-MicrowinGetIso { Write-Host "oscdimg.exe was successfully downloaded from github" } } + } elseif (Microwin-TestKitsRootPaths -adkKitsRootPath "$expectedADKPath" -adkKitsRootPath_WOW64Environ "$expectedADKPath_WOW64Environ") { + # We have to guess where oscdimg is. We'll check both values... + $peToolsPath = "" + + if ($expectedADKPath -ne "Assessment and Deployment Kit") { $peToolsPath = $expectedADKPath } + if (($peToolsPath -eq "") -and ($expectedADKPath_WOW64Environ -ne "Assessment and Deployment Kit")) { $peToolsPath = $expectedADKPath_WOW64Environ } + + Write-Host "Using $peToolsPath as the Preinstallation Environment tools path..." + # Paths change depending on platform + if ([Environment]::Is64BitOperatingSystem) { + $oscdimgPath = "$peToolsPath\Deployment Tools\amd64\Oscdimg\oscdimg.exe" + } else { + $oscdimgPath = "$peToolsPath\Deployment Tools\x86\Oscdimg\oscdimg.exe" + } + + # If it's a non-existent file, we won't continue. + if (-not (Test-Path -Path "$oscdimgPath" -PathType Leaf)) { + $oscdimgFound = $false + } + } + + if (-not ($oscdimgFound)) { + [System.Windows.MessageBox]::Show("oscdimg.exe is not found on the system. Cannot continue.") + return } Invoke-MicrowinBusyInfo -action "wip" -message "Checking disk space..." -interactive $false diff --git a/functions/microwin/Microwin-GetKitsRoot.ps1 b/functions/microwin/Microwin-GetKitsRoot.ps1 new file mode 100644 index 00000000..2736b3b6 --- /dev/null +++ b/functions/microwin/Microwin-GetKitsRoot.ps1 @@ -0,0 +1,40 @@ +function Microwin-GetKitsRoot { + <# + .SYNOPSIS + Gets the kits root path for the Windows Assessment and Deployment Kit (ADK) + .PARAMETER wow64environment + Determines whether to search in a WOW64 compatibility environment (HKLM\SOFTWARE\WOW6432Node) + .OUTPUTS + The path to the kits root + #> + + param ( + [Parameter(Mandatory = $true, Position = 0)] [bool]$wow64environment + ) + + $adk10KitsRoot = "" + + # if we set the wow64 bit on and we're on a 32-bit system, then we prematurely return the value + if (($wow64environment -eq $true) -and (-not [Environment]::Is64BitOperatingSystem)) { + return $adk10KitsRoot + } + + $regPath = "" + if ($wow64environment) { + $regPath = "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows Kits\Installed Roots" + } else { + $regPath = "HKLM:\SOFTWARE\Microsoft\Windows Kits\Installed Roots" + } + + if ((Test-Path "$regPath") -eq $false) { + return $adk10KitsRoot + } + + try { + $adk10KitsRoot = Get-ItemPropertyValue -Path $regPath -Name "KitsRoot10" -ErrorAction Stop + } catch { + Write-Host "Could not find ADK." + } + + return $adk10KitsRoot +} diff --git a/functions/microwin/Microwin-TestKitsRootPaths.ps1 b/functions/microwin/Microwin-TestKitsRootPaths.ps1 new file mode 100644 index 00000000..2188c16d --- /dev/null +++ b/functions/microwin/Microwin-TestKitsRootPaths.ps1 @@ -0,0 +1,11 @@ +function Microwin-TestKitsRootPaths { + param ( + [Parameter(Mandatory = $true, Position = 0)] [string]$adkKitsRootPath, + [Parameter(Mandatory = $true, Position = 1)] [string]$adkKitsRootPath_WOW64Environ + ) + + if (Test-Path "$adkKitsRootPath") { return $true } + if (Test-Path "$adkKitsRootPath_WOW64Environ") { return $true } + + return $false +}