Skip to content

Commit

Permalink
Add script and instructions to install the latest version of WSL when…
Browse files Browse the repository at this point in the history
… the machine is in a bad MSIX state (#11500)
  • Loading branch information
OneBlue committed Apr 23, 2024
1 parent b79d1d5 commit 52bad1f
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
20 changes: 20 additions & 0 deletions triage/config.yml
Expand Up @@ -90,6 +90,12 @@ rules:
name: user-visible-error
capture:
field3: error

- logline:
provider: Microsoft.Windows.Subsystem.Lxss
task: UserVisibleError
field3: Wsl/CallMsi/REGDB_E_CLASSNOTREG
set: msix-bad-install-state

- logline:
provider: Microsoft-Windows-Hyper-V-Chipset
Expand Down Expand Up @@ -271,3 +277,17 @@ actions:
condition: msix-install-error
debug_message: 'Found evidence of MSIX install error: $error, adding msix tag'
tag: 'msix'

- when:
condition: msix-bad-install-state
user_message: |
Your WSL installation appears to be in a bad state. Can you try running the following command to reinstall WSL (elevated powershell) and see if that solves the issue?
```
Invoke-WebRequest -UseBasicParsing "https://raw.githubusercontent.com/microsoft/WSL/master/triage/install-latest-wsl.ps1" -OutFile install-latest-wsl.ps1
Set-ExecutionPolicy Bypass -Scope Process -Force
.\install-latest-wsl.ps1
```
tag: 'msix'
50 changes: 50 additions & 0 deletions triage/install-latest-wsl.ps1
@@ -0,0 +1,50 @@
#Requires -RunAsAdministrator

# This script downloads and installs the latest version of the WSL MSI package

$ErrorActionPreference = "Stop"
Set-StrictMode -Version Latest

$release = Invoke-WebRequest 'https://api.github.com/repos/microsoft/WSL/releases/latest' | ConvertFrom-Json
$systeminfo = & systeminfo | findstr /C:"System Type"
if ($systeminfo.contains('x64'))
{
$target = '.x64.msi'
} elseif ($systeminfo.contains('arm64'))
{
$target = '.arm64.msi'
} else
{
throw 'Failed to determine system type ($systeminfo)'
}

[array]$assets = $release.assets | Where-Object { $_.name.ToLower().endswith('.x64.msi')}
if ($assets.count -ne 1)
{
throw 'Failed to find asset ($assets)'
}

$target = "$env:tmp\$($assets.name)"
Write-Host "Downloading $($assets.name) to $target"

$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$headers.Add('Accept','application/octet-stream')

Invoke-WebRequest $assets.url -Out $target -Headers $headers

$MSIArguments = @(
"/i"
$target
"/qn"
"/norestart"
)

$exitCode = (Start-Process -Wait "msiexec.exe" -ArgumentList $MSIArguments -NoNewWindow -PassThru).ExitCode
if ($exitCode -Ne 0)
{
throw "Failed to install package: $exitCode"
}

Write-Host 'Installation complete'

Remove-Item $target -Force

0 comments on commit 52bad1f

Please sign in to comment.