Created
December 20, 2022 11:09
-
-
Save mariotaku/8a9811bdc031d3388ceef98c53cce3c4 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"); | |
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