You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Irrelevant, and happens as soon as the WSL instance is started.
Repro Steps
Start any WSL instance. In my case I have a WSL v1 started without any WSLg support.
Wait
Focus is randomly stolen from your application.
I found an app somewhere at some point simply printing what process is currently getting focus. When focus is stolen I see the following line printed;
4300:C:\Program Files\WindowsApps\MicrosoftCorporationII.WindowsSubsystemForLinux_1.0.0.0_x64__8wekyb3d8bbwe\msrdc.exe | Thu 17 November 12:26:04
Often I am having an outlook window open at the time in which I am composing a mail and suddenly I cannot write in it anymore.
Expected Behavior
WSL should not steal focus.
Actual Behavior
Focus is randomly stolen
Diagnostic Logs
N/A
Reacted by Ian Currie, Dr. Greenthumb, Uilton Oliveira, Guilherme Brito, Jan, Mitchell Grice, Yifan Gu, jon8787, Leonhard Axtner, Darwin Freitag and 45 more
Reacted by Boyi C, Ram Rachum, Ian Currie, Dr. Greenthumb, Uilton Oliveira, Nikolaus Waxweiler, spiffytortoise, Endor H, Wis, Zewen Zhao and 3 more
I had this same issue today and used Focus Logger to find the culprit. It's also pointing to WSL's msrdc.exe. I've seen this happen with Notepad before, but today it seems to be related to opening Windows Explorer for me. I ran process explorer prior to starting Windows Explorer and watched several wslhost.exe processes start up, but one specifically fires up a conhost.exe process which then starts the msrdc.exe process, and that steals focus before shutting down. This all happens within seconds or less.
Reacted by Ian Currie, Christoph Krüger, jon8787, szmcdull, 𝘿𝙚𝙘𝙞𝙢𝙖𝙩𝙞𝙤𝙣, Daniel Osvaldo Rahmanto, appel, Andrei Bîscă, ijprest-haptx, STGamer24YT and 2 more
Can confirm this behavior on Windows 11, i had no issues until about 2 days ago. msrdc.exe seems to steal focus for a moment every 2 minutes, kicking me out of fullscreen applications.
The only possible cause that I could think of is that I updated my VirtualBox install from from 6 to 7.X around that time. That could be a red herring though, unless someone else can confirm that correlation.
Can confirm this behavior on Windows 11, i had no issues until about 2 days ago. msrdc.exe seems to steal focus for a moment every 2 minutes, kicking me out of fullscreen applications.
The only possible cause that I could think of is that I updated my VirtualBox install from from 6 to 7.X around that time. That could be a red herring though, unless someone else can confirm that correlation.
This problem is driving me absolutely nuts!
No matter what I'm using my computer for the focus is lost randomly every couple of minutes. Even trying to shut WSL down doesn't make any difference. I assume if I remove msrdc.exe I'll brick my system, but I really don't know what do do at this point.
Has anyone found any way of fixing this?
/edit:
While wsl --shutdown didn't do anything killing the WSL process in the task manger seems to at least give temporary relief until the process gets auto started again, e.g. by using Windows Explorer.
Disable remote credential guard in the group policy editor by:
First going to the local group policy editor, then navigating to Computer Configuration > Administrative Templates > System > Device Guard > Turn on Virtualization Based Security > Choose "Disabled" >Apply and restart pc
Been wondering what was causing it since November, thought it is from my custom keyboard layout, because one of the symptoms was that the language menu (next to the clock) would disappear in these moments.
I just uninstalled everything from my Windows 10 PC and reinstalled it, because it was so unstable. After re-installing I am still seeing the same issue. I can't even add a user to a new distribution because focus is stolen before I can enter a password for a new user.
Using Process Explorer I can see the following hierarchy when the problem occurs:
I've seen crashes in msrdc.exe in this background process when using the "Sound for remote desktop" (https://www.sound-over-rdp.com/) software. The cause of the crash was an issue in a DLL they inject in all processes, seemingly to force the output sound device. There was a way to enable crash memory dumps I think with the global flags tool, if you get such a dump may help narrow down the cause of the crash.
This has to be the most infuriating thing I have ever encountered. I can't code in IntelliJ anymore, feels like every other second something is stealing my focus. Using the Focus Logger tool I also identified the "msrdc.exe" as the cause. In the midst of typing some code the focus is just gone, then returns after a few seconds.
I just did a clean install Win11 Pro and did all the updates. Now the Computer is basically unusable.
yeah GPT gave me this powershell script and catch this thief msrdc.exe for me and point me all the way here.
and .wslconfig + shutdown temporarily gave me relief but i'm not sure whether this is a good idea because i actually need WSLg with Arch and Colmap (probably)
Add-Type @"
using System;
using System.Runtime.InteropServices;
public class Win32 {
[DllImport("user32.dll")]
public static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")]
public static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint processId);
}
"@
$lastPid = 0
while ($true) {
$hwnd = [Win32]::GetForegroundWindow()
$procId = 0
[Win32]::GetWindowThreadProcessId($hwnd, [ref]$procId) | Out-Null
if ($procId -ne $lastPid -and $procId -ne 0) {
$p = Get-Process -Id $procId -ErrorAction SilentlyContinue
"$(Get-Date -Format HH:mm:ss.fff) FG → $($p.ProcessName) ($procId)"
$lastPid = $procId
}
Start-Sleep -Milliseconds 50
}
Kovács Péter (@vectorkovacspeter) What happens if the window title changes but the process name stays the same? Wouldn't it be a window focus change in the log? Why couldn't you just have $currentWindow/$lastWindow keep track of the Window Handle $hwnd for current window? (or better yet, Process ID)
Also a thing to note is C# now has single file improvements, so you could (if you wanted), have the entire script in a single .cs file, and use dotnet run with it. :)
Dennis Fehr (@cyraid) its not a coding tutorial or a polished product or some opensource ppull-request, just AI crap good enogh for me, to track what happens, and find the root cause whitin 5 min, and just post it to help thoose who need it ;)
But thanks for the review, I told it to the modell who wrote it :D
Every 30 seconds like clockwork; and it started happening so arbitrarily. I had WSL installed and used it for ... months at this point. What changed? A few weeks ago, I cloned some repos and compiled them under Ubuntu (WSL). No issues up until yesterday or so. It's insane. How can this still be an issue after four years? An invisible, untracable app playing pranks. I thought I had caught some malware randomly. Like the others, I used a similar "FocusThief" logger via PowerShell script. W10 Pro 22H2.
I couldn't make the guiApplications=false stick. First mistake, accidentally omited the [wsl2] section header. Not sure if that worked already. One other niche: Been using Everything (voidtools) search util. Recently, probably around the time this bug started occuring, I added \wsl$.. as an explicitly indexed folder.. So I can search the tiny distro quickly without pulling up a file explorer each time. Unchecked "Attempt to monitor changes" for its folder settings (Settings > Indexes > Folders > \wsl$..). For me, I think that's what kept waking the gui subsystem 😡
How is this still a problem almost 4 years later? I was getting this since basically forever and it was annoying when it happened to my IDE, but it's now also happening when I am playing fullscreen games and they keep losing all input when it happens... pretty annoying. So I decided to check what exactly it is via Focus Logger and found this to be the culprit.
I don't have voidtools Everything, so it's clearly something else also triggers an WSL conhost.
@korypostma, what tool did you use to get your focus output?
Sorry, I didn't see the tag until now, it was a custom python script:
# Import necessary librariesimportwin32guiimportwin32processimportpsutilimporttimefromdatetimeimportdatetime# Function to get the title of a window given its handledefget_window_title(hwnd):
""" Retrieves the text of the specified window's title bar (if it has one). :param hwnd: The handle to the window. :return: The window title as a string. """returnwin32gui.GetWindowText(hwnd)
# Function to get the process name from a process ID (PID)defget_process_name(pid):
""" Retrieves the name of the process associated with the given PID. :param pid: The Process ID. :return: The process name as a string, or "N/A" if not found. """try:
process=psutil.Process(pid)
returnprocess.name()
exceptpsutil.NoSuchProcess:
return"N/A"# Function to get the command line arguments of a processdefget_process_command_line(pid):
""" Retrieves the command line arguments of the process associated with the given PID. :param pid: The Process ID. :return: The command line arguments as a string, or "N/A" if not found. """try:
process=psutil.Process(pid)
return" ".join(process.cmdline())
exceptpsutil.NoSuchProcess:
return"N/A"exceptException:
return"N/A"# Catch other potential errors# Function to get parent process informationdefget_parent_process_info(pid):
""" Retrieves the name and PID of the parent process for a given PID. :param pid: The Process ID. :return: A tuple (parent_process_name, parent_pid) or ("N/A", "N/A") if not found. """try:
process=psutil.Process(pid)
parent_process=process.parent()
ifparent_process:
returnparent_process.name(), parent_process.pidelse:
return"N/A", "N/A"# No parent process (e.g., initial system processes)exceptpsutil.NoSuchProcess:
return"N/A", "N/A"exceptException:
return"N/A", "N/A"# Catch other potential errorsdefmonitor_active_window():
""" Monitors the active window and prints its name, application name, parent process, command line arguments, and the time of focus change. """print("Starting window focus monitor...")
print("Press Ctrl+C to stop.")
last_active_window_hwnd=0last_active_window_title=""last_process_name=""last_parent_process_name=""# Not strictly needed for logic, but good for trackinglast_command_line=""try:
whileTrue:
# Get the handle of the foreground windowcurrent_active_window_hwnd=win32gui.GetForegroundWindow()
# Check if the active window has changedifcurrent_active_window_hwnd!=last_active_window_hwnd:
# Get the window titlecurrent_window_title=get_window_title(current_active_window_hwnd)
# Get the process ID of the window# win32process.GetWindowThreadProcessId returns a tuple (thread_id, process_id)_, pid=win32process.GetWindowThreadProcessId(current_active_window_hwnd)
# Get the process namecurrent_process_name=get_process_name(pid)
# Get the command line argumentscurrent_command_line=get_process_command_line(pid)
# Get the parent process infoparent_process_name, parent_pid=get_parent_process_info(pid)
# Get the current timecurrent_time=datetime.now().strftime("%Y-%m-%d %H:%M:%S")
# Print the informationprint(f"[{current_time}] Focus Changed:")
print(f" Window Title : '{current_window_title}'")
print(f" Application : '{current_process_name}' (PID: {pid})")
print(f" Command Line Args : '{current_command_line}'") # New line for command lineprint(f" Parent Process : '{parent_process_name}' (PID: {parent_pid})")
print("-"*40) # Separator for readability# Update the last active window detailslast_active_window_hwnd=current_active_window_hwndlast_active_window_title=current_window_titlelast_process_name=current_process_namelast_command_line=current_command_line# last_parent_process_name = parent_process_name # Optional: for tracking if needed later# Wait for a short period before checking again to reduce CPU usagetime.sleep(0.5)
exceptKeyboardInterrupt:
print("\nWindow focus monitor stopped.")
exceptExceptionase:
print(f"An error occurred: {e}")
if__name__=="__main__":
# Instructions for the user:# 1. Ensure Python is installed.# 2. Install required libraries using pip:# pip install pywin32 psutil# 3. Run this script from a command prompt:# python your_script_name.pymonitor_active_window()
Apparently, if Sublime Text v4215 has opened a file from \\wsl.localhost, it may frequently lose focus when returning to it. I've tried monitoring windows focus, and got the following when I switched to a Sublime Text window:
============== New program has foreground window ============
C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
============== New program has foreground window ============
D:\Programs\Installed\Sublime Text\sublime_text.exe
============== New program has foreground window ============
C:\Program Files\WSL\msrdc.exe
The above is an output of a program found Focusmonitor by Nicholas Chapman (@Ono-Sendai) , thank you very much! Oh! What if the program would also print the precise time of the event? ^^"
It's worth to mention that the layout also disappears from the Taskbar when Sublime Text loses the focus suddenly. Perhaps similar to the above case mentioned:
...because one of the symptoms was that the language menu (next to the clock) would disappear in these moments.
Four years on and it's still happening. Here's some PowerShell code that Gemini suggested on how to confirm that msrdc.exe indeed steals your focus:
Add-Type @"
using System;
using System.Runtime.InteropServices;
public class FocusTracker {
[DllImport("user32.dll")] public static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll")] public static extern uint GetWindowThreadProcessId(IntPtr hWnd, out uint lpdwProcessId);
}
"@
$lastHwnd = [IntPtr]::Zero
Write-Host "Monitoring focus changes... Press Ctrl+C to stop." -ForegroundColor Cyan
while ($true) {
$hwnd = [FocusTracker]::GetForegroundWindow()
if ($hwnd -ne $lastHwnd -and $hwnd -ne [IntPtr]::Zero) {
$pidOut = 0
[void][FocusTracker]::GetWindowThreadProcessId($hwnd, [ref]$pidOut)
$proc = Get-Process -Id $pidOut -ErrorAction SilentlyContinue
$time = Get-Date -Format "HH:mm:ss.fff"
Write-Host "[$time] Process: $($proc.ProcessName) (PID: $pidOut) | Title: '$($proc.MainWindowTitle)'"
$lastHwnd = $hwnd
}
Start-Sleep -Milliseconds 150
}
• Trigger the issue. Leave the PowerShell terminal (with the above code) running in the background and use your computer normally until your window loses focus.
• Check the output. Look at the timestamp when the interruption occurred to see the exact executable name and process ID (PID) that grabbed focus, even if the window vanished immediately. Press Ctrl + C in the terminal to stop the script.
Activity
mha42 commentedon Nov 17, 2022
focus.zip
I am attaching the focus tool incl source code.
scottrudy commentedon Dec 6, 2022
I had this same issue today and used Focus Logger to find the culprit. It's also pointing to WSL's msrdc.exe. I've seen this happen with Notepad before, but today it seems to be related to opening Windows Explorer for me. I ran process explorer prior to starting Windows Explorer and watched several wslhost.exe processes start up, but one specifically fires up a conhost.exe process which then starts the msrdc.exe process, and that steals focus before shutting down. This all happens within seconds or less.
maxhoesel commentedon Dec 23, 2022
Can confirm this behavior on Windows 11, i had no issues until about 2 days ago. msrdc.exe seems to steal focus for a moment every 2 minutes, kicking me out of fullscreen applications.
The only possible cause that I could think of is that I updated my VirtualBox install from from 6 to 7.X around that time. That could be a red herring though, unless someone else can confirm that correlation.
mha42 commentedon Dec 23, 2022
I don't run VirtualBox at all here.
MarcoBrieden commentedon Dec 26, 2022
This problem is driving me absolutely nuts!
No matter what I'm using my computer for the focus is lost randomly every couple of minutes. Even trying to shut WSL down doesn't make any difference. I assume if I remove msrdc.exe I'll brick my system, but I really don't know what do do at this point.
Has anyone found any way of fixing this?
/edit:
While
wsl --shutdowndidn't do anything killing the WSL process in the task manger seems to at least give temporary relief until the process gets auto started again, e.g. by using Windows Explorer.Lyqed commentedon Jan 8, 2023
Two possible solutions I found are:
backup the msrdc.exe file and then delete it.
Disable remote credential guard in the group policy editor by:
First going to the local group policy editor, then navigating to Computer Configuration > Administrative Templates > System > Device Guard > Turn on Virtualization Based Security > Choose "Disabled" >Apply and restart pc
ftvkyo commentedon Jan 8, 2023
Can confirm, Windows 11 Pro, 22H2, 22621.963.
Been wondering what was causing it since November, thought it is from my custom keyboard layout, because one of the symptoms was that the language menu (next to the clock) would disappear in these moments.
zadjii-msft commentedon Jan 18, 2023
Craig Loewen (@craigloewen-msft) Any updates on this (or the other focus stealing threads)? I'm trying to rule out WSL from the cause of microsoft/terminal#13388, but that's proven... tricky.
scottrudy commentedon Jan 18, 2023
I just uninstalled everything from my Windows 10 PC and reinstalled it, because it was so unstable. After re-installing I am still seeing the same issue. I can't even add a user to a new distribution because focus is stolen before I can enter a password for a new user.
Using Process Explorer I can see the following hierarchy when the problem occurs:
Location of msrdc.exe
C:\Program Files\WindowsApps\MicrosoftCorporationII.WindowsSubsystemForLinux_1.0.3.0_x64__8wekyb3d8bbwe\msrdc.exe
Command line argument
msrdc.exe /v:0C22B93D-1735-409E-86C1-A57BAABA42C2 /hvsocketserviceid:4C7A87FC-FACB-11E6-BD58-64006A7986D3 /silent /wslg /plugin:WSLDVC_PACKAGE /wslgsharedmemorypath:WSL\0C22B93D-1735-409E-86C1-A57BAABA42C2\wslg "C:\Program Files\WindowsApps\MicrosoftCorporationII.WindowsSubsystemForLinux_1.0.3.0_x64__8wekyb3d8bbwe\wslg.rdp"
rwasef1830 commentedon Jan 18, 2023
I've seen crashes in msrdc.exe in this background process when using the "Sound for remote desktop" (https://www.sound-over-rdp.com/) software. The cause of the crash was an issue in a DLL they inject in all processes, seemingly to force the output sound device. There was a way to enable crash memory dumps I think with the global flags tool, if you get such a dump may help narrow down the cause of the crash.
scottrudy commentedon Jan 18, 2023
The issue I am seeing today shows the following in Problem Details
Source
Remote Desktop
Summary
Stopped working
Date
1/18/2023 12:45 PM
Status
Report sent
Description
Faulting Application Path: C:\Program Files\WindowsApps\MicrosoftCorporationII.WindowsSubsystemForLinux_1.0.3.0_x64__8wekyb3d8bbwe\msrdc.exe
Problem signature
Problem Event Name: MoAppCrash
Package Full Name: MicrosoftCorporationII.WindowsSubsystemForLinux_1.0.3.0_x64__8wekyb3d8bbwe
Application Name: praid:msrdc
Application Version: 1.2.3575.0
Application Timestamp: 633c8bef
Fault Module Name: KERNELBASE.dll
Fault Module Version: 10.0.19041.2364
Fault Module Timestamp: 5b7d4d22
Exception Code: c06d007e
Exception Offset: 000000000002cd29
OS Version: 10.0.19044.2.0.0.256.4
Locale ID: 1033
Additional Information 1: 3895
Additional Information 2: 3895d839a7fe3f6903b9cbca03bd030e
Additional Information 3: 3981
Additional Information 4: 3981f255f8e6b8e54242bfc4bce248e4
Extra information about the problem
Bucket ID: 1bdacafa384471b8e7d131b0fc19a97e (0)
thheller commentedon Jan 27, 2023
This has to be the most infuriating thing I have ever encountered. I can't code in IntelliJ anymore, feels like every other second something is stealing my focus. Using the Focus Logger tool I also identified the "msrdc.exe" as the cause. In the midst of typing some code the focus is just gone, then returns after a few seconds.
I just did a clean install Win11 Pro and did all the updates. Now the Computer is basically unusable.
thheller commentedon Jan 27, 2023
I found #523, and created the
$HOME/.wslconfig(windows home,C:\Users\..\.wslconfignot in linux) withThat at least seems to bring some relief.
meiskam commentedon Jan 28, 2023
having the same issue
neither
wsl --shutdownnor$HOME/.wslconfig .. guiApplications=falsehelped66 remaining items
blkot commentedon Jan 26, 2026
yeah GPT gave me this powershell script and catch this thief msrdc.exe for me and point me all the way here.
and .wslconfig + shutdown temporarily gave me relief but i'm not sure whether this is a good idea because i actually need WSLg with Arch and Colmap (probably)
AJolly commentedon Feb 6, 2026
Still getting this issue all the time
vectorkovacspeter commentedon Feb 12, 2026
same on here latest windows 11, thats crazy...
my detective script:
cyraid commentedon Feb 12, 2026
Kovács Péter (@vectorkovacspeter) What happens if the window title changes but the process name stays the same? Wouldn't it be a window focus change in the log? Why couldn't you just have
$currentWindow/$lastWindowkeep track of the Window Handle$hwndfor current window? (or better yet, Process ID)Also a thing to note is C# now has single file improvements, so you could (if you wanted), have the entire script in a single .cs file, and use
dotnet runwith it. :)vectorkovacspeter commentedon Feb 13, 2026
Dennis Fehr (@cyraid) its not a coding tutorial or a polished product or some opensource ppull-request, just AI crap good enogh for me, to track what happens, and find the root cause whitin 5 min, and just post it to help thoose who need it ;)
But thanks for the review, I told it to the modell who wrote it :D
cyraid commentedon Feb 13, 2026
Kovács Péter (@vectorkovacspeter) lol fair enough! You show that AI bot! Get em'!
GyllenByte commentedon Mar 1, 2026
Every 30 seconds like clockwork; and it started happening so arbitrarily. I had WSL installed and used it for ... months at this point. What changed? A few weeks ago, I cloned some repos and compiled them under Ubuntu (WSL). No issues up until yesterday or so. It's insane. How can this still be an issue after four years? An invisible, untracable app playing pranks. I thought I had caught some malware randomly. Like the others, I used a similar "FocusThief" logger via PowerShell script. W10 Pro 22H2.
I couldn't make the guiApplications=false stick. First mistake, accidentally omited the [wsl2] section header. Not sure if that worked already. One other niche: Been using Everything (voidtools) search util. Recently, probably around the time this bug started occuring, I added \wsl$.. as an explicitly indexed folder.. So I can search the tiny distro quickly without pulling up a file explorer each time. Unchecked "Attempt to monitor changes" for its folder settings (Settings > Indexes > Folders > \wsl$..). For me, I think that's what kept waking the gui subsystem 😡
slashy commentedon May 23, 2026
How is this still a problem almost 4 years later? I was getting this since basically forever and it was annoying when it happened to my IDE, but it's now also happening when I am playing fullscreen games and they keep losing all input when it happens... pretty annoying. So I decided to check what exactly it is via Focus Logger and found this to be the culprit.
I don't have voidtools Everything, so it's clearly something else also triggers an WSL conhost.
korypostma commentedon Jun 2, 2026
Sorry, I didn't see the tag until now, it was a custom python script:
lidonwonk commentedon Jun 11, 2026
just encounter this. shocked at it hasn't been fixed.it's really annoying.so i disabled wslg and use VcXsrv now
liugangnhm commentedon Jul 29, 2026
ms is stupid
campbell-reid-displayr commentedon Aug 11, 2026
Another victim of this annoying thing. Glad other people vibe coded tools to figure this out too lol.
TheDirigible commentedon Aug 17, 2026
Still happening 4 years later. Maddening.
serious-angel commentedon Oct 9, 2026
Wonderful day!
Apparently, if Sublime Text v4215 has opened a file from
\\wsl.localhost, it may frequently lose focus when returning to it. I've tried monitoring windows focus, and got the following when I switched to a Sublime Text window:The above is an output of a program found Focusmonitor by Nicholas Chapman (@Ono-Sendai) , thank you very much! Oh! What if the program would also print the precise time of the event? ^^"
It's worth to mention that the layout also disappears from the Taskbar when Sublime Text loses the focus suddenly. Perhaps similar to the above case mentioned:
I am not the most frequent on Windows (am mainly at Linux), but I'll try do more research if required.
rio197 commentedon Nov 15, 2026
Four years on and it's still happening. Here's some PowerShell code that Gemini suggested on how to confirm that msrdc.exe indeed steals your focus:
• Trigger the issue. Leave the PowerShell terminal (with the above code) running in the background and use your computer normally until your window loses focus.
• Check the output. Look at the timestamp when the interruption occurred to see the exact executable name and process ID (PID) that grabbed focus, even if the window vanished immediately. Press Ctrl + C in the terminal to stop the script.