-
-
Save pnck/5a99adc0b443941b07db198f238de004 to your computer and use it in GitHub Desktop.
Fix WSL Connection Issue Caused by Winsock
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Requires -RunAsAdministrator | |
# Fix for https://github.com/microsoft/WSL/issues/4177 | |
$MethodDefinition = @' | |
[DllImport("ws2_32.dll", CharSet = CharSet.Unicode)] | |
public static extern int WSCSetApplicationCategory([MarshalAs(UnmanagedType.LPWStr)] string Path, uint PathLength, [MarshalAs(UnmanagedType.LPWStr)] string Extra, uint ExtraLength, uint PermittedLspCategories, out uint pPrevPermLspCat, out int lpErrno); | |
'@ | |
$Ws2Spi = Add-Type -MemberDefinition $MethodDefinition -Name 'Ws2Spi' -PassThru | |
$WslLocation = Get-AppxPackage MicrosoftCorporationII.WindowsSubsystemForLinux | Select-Object -expand InstallLocation | |
$Executables = ("wsl.exe", "wslservice.exe", "wslg.exe", "wslhost.exe"); | |
foreach ($Exe in $Executables) { | |
$ExePath = "${WslLocation}\${Exe}"; | |
$ExePathLength = $ExePath.Length; | |
$PrevCat = $null; | |
$ErrNo = $null; | |
if ($Ws2Spi::WSCSetApplicationCategory($ExePath, $ExePathLength, $null, 0, [uint32]"0x80000000", [ref] $PrevCat, [ref] $ErrNo) -eq 0) { | |
Write-Output "Added $ExePath!"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment