From 97369cc9d9d085d57abd9c32072573bd1cf4aed1 Mon Sep 17 00:00:00 2001 From: Matthew John Cheetham Date: Tue, 3 Feb 2026 13:47:43 +0000 Subject: [PATCH] wslutils: guard against failure to launch pwsh Let's not crash the process if we are unable to launch PowerShell to determine the Windows session ID. Signed-off-by: Matthew John Cheetham --- src/shared/Core/WslUtils.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/shared/Core/WslUtils.cs b/src/shared/Core/WslUtils.cs index 1db63d329..977677d6e 100644 --- a/src/shared/Core/WslUtils.cs +++ b/src/shared/Core/WslUtils.cs @@ -195,8 +195,16 @@ public static int GetWindowsSessionId(IFileSystem fs) const string script = @"(Get-Process -ID $PID).SessionId"; using (Process proc = CreateWindowsShellProcess(fs, WindowsShell.PowerShell, script)) { - proc.Start(); - proc.WaitForExit(); + try + { + proc.Start(); + proc.WaitForExit(); + } + catch + { + // Unable to start the process, return unknown session ID + return -1; + } if (proc.ExitCode == 0) {