Skip to content
This repository has been archived by the owner on Jan 25, 2024. It is now read-only.

Commit

Permalink
fix(msi): improve and simplify pre-install check
Browse files Browse the repository at this point in the history
  • Loading branch information
mriedmann committed Apr 17, 2023
1 parent 8facaf9 commit e69439e
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions msi/install/check.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,19 @@ Set-StrictMode -Version 3
Add-Type -AssemblyName Microsoft.VisualBasic

if(((Get-ChildItem "HKCU:\SOFTWARE\Classes\Local Settings\Software\Microsoft\Windows\CurrentVersion\AppModel\SystemAppData") -match "MicrosoftCorporationII.WindowsSubsystemForLinux_8wekyb3d8bbwe").count -eq 0) {
[Microsoft.VisualBasic.Interaction]::MsgBox("WSL2 not installed!`n`nCheck your windows-updates and run 'wsl --install -n' in an elevated shell, reboot and start this install again.", 'OKOnly,SystemModal,Critical', "DockerInWSL Installation Error") | Out-Null
[Microsoft.VisualBasic.Interaction]::MsgBox("WSL2 not installed!`n`nCheck your windows-updates and run 'wsl --install --no-distribution' in an elevated shell, reboot and start this install again.", 'OKOnly,SystemModal,Critical', "DockerInWSL Installation Error") | Out-Null
throw "WSL2 not installed"
}

# Hotfix for https://github.com/microsoft/WSL/issues/7767
$wslHelpText = (((& wsl --help) -join ' ').ToCharArray() | % {$result = ""} { $result += ($_ | Where-Object { $_ -imatch "[ -a-z_]" }) } { $result })
if($wslHelpText.IndexOf("--import") -lt 0) {
[Microsoft.VisualBasic.Interaction]::MsgBox("WSL2 not initialized!`n`nTry running 'wsl --install -n' in an elevated shell, reboot and start this install again.", 'OKOnly,SystemModal,Critical', "DockerInWSL Installation Error") | Out-Null
[Microsoft.VisualBasic.Interaction]::MsgBox("WSL2 not initialized!`n`nTry running 'wsl --install --no-distribution' in an elevated shell, reboot and start this install again.", 'OKOnly,SystemModal,Critical', "DockerInWSL Installation Error") | Out-Null
throw "WSL2 not initialized"
}

if((Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion").ProductName -match "Windows 11"){
# We skip checks because Win11 has wsl2 already installed.
} else {
# Check if WSL Update is installed. (Not using Win32_Product to avoid WMI problems)
$wslUpdatePackageName = "Windows Subsystem for Linux Update"
$apps = @()
$apps += Get-ItemProperty "HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*" # 32 Bit
$apps += Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*" # 64 Bit
$appNames = $apps | Where-Object { $_.PSobject.Properties.Name.Contains("DisplayName") } | Select-Object -ExpandProperty DisplayName
if (($appNames -match $wslUpdatePackageName | Measure-Object).Count -le 0) {
[Microsoft.VisualBasic.Interaction]::MsgBox("No '$wslUpdatePackageName' found!`nPlease visit https://docs.microsoft.com/en-us/windows/wsl/install-manual and install the update if this installation fails.", 'OKOnly,SystemModal,Exclamation', "DockerInWSL Installation Warning") | Out-Null
}
wsl --status | Out-Null
if(-not $?){
[Microsoft.VisualBasic.Interaction]::MsgBox("WSL2 not working!`n`nTry to reboot and start this install again. Please create an issue on GitHub if you see this error after installing wsl and rebooting.", 'OKOnly,SystemModal,Critical', "DockerInWSL Installation Error") | Out-Null
throw "WSL2 not working"
}

0 comments on commit e69439e

Please sign in to comment.