32

Something is shifting (stealing) focus from my active window (active program) in my Windows, as I'm currently using it.

I have the same problem as described in this question, with a few exceptions:

  1. I observed this behavior on (at least) two different computers, so this is not a machine-specific.

  2. One of mentioned computers has Windows 7 HE 64-bit another has Windows 7 Pro 32-bit, so this problem is not specific to a particular version of Windows or to a particular hardware platform.

  3. Sometimes focus is lost for good (have to click on window to continue using it), sometimes it is just shifted to some another background process (?) and returns after about 2-3 seconds.

  4. I haven't been installing anything new on any of these computers for past few weeks (except for Windows Update and other automated updades like Chrome browser auto-update) and certainly mentioned probles started to happen many days after last install.

Current behavior of my computer is really weird and the entire thing become annoying. Examples:

  1. I'm selecting some text in Chrome and actually see, that selection color changes from blue (selection in an active windows) to gray (selection in inactive window).

  2. I'm editing some document in Word, Notepad++ or an e-mail in Gmail in Chrome and edit process either stops for a few seconds (when focus shifts) for is ended permanently (focus lost for good).

I have active, updated and working Microsoft Security Essentials and it does not report anything unusual.

I had a feeling, that it most often occurs in Google Chrome. At first I was so sure, that I was nearly ready to accuse some of last updates of this browser. But it turned out, that I noticed this unusually often in Chrome, because this is my most often used program.

Does anyone have or had similar problems or have any idea, what can be causing this or how to fix this?

2
  • 2
    Does the problem happen in Safe Mode too (with or without networking) too? Start msconfig, and select the Startup tab. What programs are there?
    – and31415
    Jan 30, 2014 at 15:52
  • 2
    It is very hard to "catch" described problem, because it does not happens too often. For example -- no trace for past two days. So I would have to work days in Safe Mode to try to "catch" this. But, thanks for the idea. Also, see my answer below.
    – trejder
    Jan 31, 2014 at 7:55

21 Answers 21

20

As and31415 advised me, I took a careful look at what is in my Startup tab of msconfig program, but found nothing unusual.

It is now clear that this is 99% caused by some external program (though not noticed before and though I haven't installed anything new recently), not by Windows. This is the most important point for me here.

I googled a little bit more and got some ideas / advice, namely that I should try to press Alt+F4 immediately after I notice a steal of a focus. This should exit process that could cause this focus stealth. Then, I may try to use Process Monitor from Sysinternals package to trace the process that has just exited.

This may give me some idea of what is causing this problem.

6
  • 2
    From msconfig, select the Services tab and enable the Hide all Microsoft services. Check that too. Here's an official KB article which can be useful: Perform a clean startup to determine whether background programs are interfering with your game or program. Also, even if you don't see anything unusual, I think it would be a good idea to list all third party startup items and services you got.
    – and31415
    Feb 1, 2014 at 21:22
  • @trejder, did you need to download technet.microsoft.com/en-us/sysinternals/bb896645 or something else, or are you referring to a built-in feature of Windows that lets you look at a list of processes that recently exited? Thanks!
    – Ryan
    Aug 18, 2016 at 23:50
  • @Ryan Nope, as in answer -- Process Monitor from Sysinternals package.
    – trejder
    Aug 27, 2016 at 19:31
  • 3
    When using Process Monitor, go to the Filter menu and add the following filter: Operation is not Process Exit then Exclude. My touchpad driver was throwing an error and trying to report it with Windows Problem Reporting. Thank %#!@ for these Q&A sites or else I would have destroyed my laptop. Nov 2, 2016 at 9:06
  • I just had this happen to me. Turned out to be C:\Program Files (x86)\ViveSetup\PCClient\HTCVRMarketplaceUserContextHelper.exe - a program for the HTC Vive. I deleted the whole directory. I suspect it is a problem with their update earlier this week
    – Deleted
    Mar 3, 2017 at 0:52
15

I programmed a C# program to monitor fluctuating processes. Here is the code if someone needs to find out what process is causing this problem.

using System;
using System.Diagnostics;
using System.Linq;

namespace ProcessMonitor
{
    class Program
    {
        static void Main(string[] args)
        {
            var lastPros = Process.GetProcesses().Select((x) => x.Id).ToList();
            var oldProcessList = Process.GetProcesses();
            while (true)
            {
                var processlist = Process.GetProcesses();

                var currentPros = processlist.Select(x => x.Id).ToList();
                var diff = lastPros.Except(currentPros).ToList();
                Console.ForegroundColor = ConsoleColor.Red;

                var pro = oldProcessList.Where(x => diff.Contains(x.Id)).ToList();

                if (diff.Count == 0)
                {
                    pro = processlist.Where((x) => diff.Contains(x.Id)).ToList();
                    diff = currentPros.Except(lastPros).ToList();
                    Console.ForegroundColor = ConsoleColor.Green;
                    pro = processlist.Where((x) => diff.Contains(x.Id)).ToList();
                }
                foreach (var oldPid in diff)
                {
                    Console.Write("PID {0}", oldPid);
                    try
                    {
                        Console.WriteLine(" name {0}", pro.Where((x) => x.Id == oldPid).ToList()[0].ProcessName);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine($" Hit exception {e}");
                    }
                }
                if (diff.Count > 0)
                {
                    lastPros = currentPros;
                    oldProcessList = processlist;
                }
                System.Threading.Thread.Sleep(100);
            }
        }
    }
}

Output sample showing process starting (green) and terminating (red)

Output sample

4
  • 15
    Good idea and nice piece of code. But, since this is a site for users, not developers (this is Super User, not Stack Overflow), then you should add some explanation on how non-C#-developer is able to run your code?
    – trejder
    Feb 17, 2016 at 17:06
  • I created an improved version of this and put it in my own answer, including the answers to your questions, @trejder.
    – Palec
    Jul 9, 2017 at 14:51
  • 1
    probably convert this into PowerShell which doesn't need a C# compiler?
    – phuclv
    Jul 3, 2018 at 6:55
  • @phuclv sure go ahead :D Jul 3, 2018 at 11:58
12

The focus is probably stolen by a buggy background task. It opens a window, which steals focus, and it is very quickly closed, but the focus does not return. Lately, Microsoft Office had such a bug.

To discover such processes, you can use tools like Window Focus Logger (mirror) or a custom C# program similar to Process Monitor:

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

namespace ProcessMonitor
{
    class Program
    {
        const int pollDelay = 100;

        static void Main(string[] args)
        {
            var lastProcesses = GetDescriptions();
            while (true)
            {
                System.Threading.Thread.Sleep(pollDelay);
                var now = DateTime.Now;
                var processes = GetDescriptions();

                var started = processes.Except(lastProcesses);
                var stopped = lastProcesses.Except(processes);

                foreach (var p in started)
                {
                    Print(now, p, ConsoleColor.Green);
                }
                foreach (var p in stopped)
                {
                    Print(now, p, ConsoleColor.Red);
                }

                lastProcesses = processes;
            }
        }

        static void Print(DateTime dateTime, ProcessDescription process,
            ConsoleColor color)
        {
            Console.ForegroundColor = color;
            Console.WriteLine("{0:hh\\:mm\\:ss\\.ff}\tPID {1}\t{2}",
                dateTime.TimeOfDay, process.Id, process.Description);
            Console.ResetColor();
        }

        static List<ProcessDescription> GetDescriptions()
        {
            return Process.GetProcesses().Select(x => GetDescription(x)).ToList();
        }

        static ProcessDescription GetDescription(Process p)
        {
            int pid = -1;
            string description;
            try
            {
                pid = p.Id;
                description = p.ProcessName;
            }
            catch (Exception e)
            {
                description = "Hit exception " + e;
            }
            return new ProcessDescription { Id = pid, Description = description };
        }

        struct ProcessDescription
        {
            public int Id;
            public string Description;

            public override bool Equals(object obj)
            {
                return obj != null && Id == ((ProcessDescription)obj).Id;
            }
            public override int GetHashCode()
            {
                return Id.GetHashCode();
            }
        }
    }
}

Polished and bugfixed version of the code provided by Omar Alshaker. Also does not require C# 6. Requires .NET 3.5 or newer.

You can compile it using the C# compiler (csc.exe) that comes with your .NET Framework installation and run the resulting executable to get a real-time log of processes that start (green) or end (red). Use Ctrl + C to terminate it.


To find the compiler, run where /R %windir%\Microsoft.NET csc.exe. Pick the one from the latest .NET version installed, no matter whether 32b or 64b. Save the C# code in Program.cs and compile it to Program.exe:

C:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe Program.cs
6
  • This code gives me the error "The type or namespace 'Process' could not be found". So I needed to add a reference to System.dll. Mar 28, 2018 at 12:15
  • Strange, @Wilson. Which version of csc.exe are you using?
    – Palec
    Mar 28, 2018 at 17:45
  • 1
    By the way, the command line will be csc.exe -reference:System.dll Program.cs then. See -reference C# compiler option docs.
    – Palec
    Mar 29, 2018 at 12:14
  • I have Microsoft (R) Visual C# Compiler version 2.6.0.62329 (5429b35d) Mar 29, 2018 at 12:19
  • That version seems to be from an older build of VS 2017 (or its build tools). I cannot reproduce the problem with current VS 2017 (15.6.4, csc -version 2.7.0.62715 (db02128e)). Still, thanks for sharing the issue and its solution.
    – Palec
    Mar 29, 2018 at 12:31
5

In my case it was that wermgr.exe (Windows error reporting) started again and again. I followed the below solution to stop it from starting automatically, and that solved the problem.

  1. Start button -> In the search box type Action center -> Enter.
  2. Click on the arrow next to Maintenance to expand.
  3. Under Check for solutions to problem reports, click on Settings.
  4. Click on Change report settings for all users.
  5. Check the radio button next to Each time a problem occurs, ask me before checking for solution.
  6. OK your way out, by clicking OK.
3

The Hint with using Alt+F4 to exit the interrupting program worked well. Instead of tracing the just exited program with SysInternal's ProcessManager, I did traced the program as follows:

  1. Open Task manager
  2. Take a screenshot of open processes
  3. Switch to Browser, Mail etc and "wait on focus loss"
  4. Press Alt+F4 to exit the interrupting program
  5. Go to Task manager and compare open processes with screenshot
  6. The now "missing" process caused the problem

In my case it was twcu.exe, a program that starts with TP-Link Configuration tool. It is used by external WIFI-USB Sticks. As reported here (twcu.exe at file.net) and here (twcu.exe at computerbase.de [german]), TP-Link Configuration tool is not needed for the WIFI connection itself. I removed it from Autostart (msconfig > system start), restarted the computer and it still connects to the WIFI flawless - and the focus loss problems are gone!

2

I removed NMBgMonitor.exe from startup services to solve the issue.

I've also had the same problem with the Google Chrome window losing focus for several seconds and then returning. By watching the task manager services tab, I noticed that whenever focus was lost, NMBgMonitor was active (it has something to do with Nero).

2

in my case, and probably all lenovo pc's/laptop cases, the issue was with lenovo svcguihlpr.exe which start working every few minutes and taking the focus without UI shown... this process is Lenovo Access Connections app that gives nice ui for managing wifi and broadband networks.. i never used it, i even removed it ui from the taskbar but it still work...

today i found that it was the issue and uninstalled it!

so much fun..

by the way, i found it by doing the most idiotic thing possible, taking my phone, starting a video recording the screen were i run task manager, and continue my work.. once the focus lost i waited a second, stopped the record and checked which processes moved up, svcguihlpr was on the top for less than a second..

hope it will help others.

1
  • it was hilarious to say "so much fun" about not having an issue xD Jun 15, 2018 at 22:06
2

I had this problem, I thought the timing was random but it was not,

in my case it was as trivial as: wallpaper changes!
I had a slideshow as wallpaper and every time it changes, the focus goes to the desktop!

I hope this might be the case for someone reading the comments and it would be as simple as this.

(I do not know if microsoft will ever fix this, since Im having the issue on the latest build of windows 10 (1803 - 17134.112))

1

I had window losing focus constantly too. Read that someone managed to track WerSvc is causing problem by using a logger. Even if that is in fact a Windows Error Reporting Service, but i tried to disable it in Windows Task Manager - Services - Services.

Then the losing focus problem stopped.

Maybe you guys can try it.

1

This problem drove me crazy! So I decided to write a program to tell me who or what is taking focus away from my program. Real annoying when you're playing Age of Empires and the game goes to the desktop randomly.

Here are the findings....

Verizon! Yes, I had installed some Verizon helper app and it was the culprit!
Go into - Control Panel -> Programs and Features
and uninstall anything relating to Verizon.

I forget the names of the programs, usually started with a Vz..., and there's a service too IW... I honestly forget since I couldn't wait to kill whatever was on my machine from them (it drove me that crazy), but when you uninstall the Verizon app., the problem goes away.

1

In my case, I fixed the problem by going to the windows process manager, and checking if any programmes are being launched and closed constantly. I could notice that a program I downloaded (I think it was called windows 8 start) was restarting every 7 seconds. I deleted everything related to it, and it worked!

1

I was having the problem of the active window losing focus every few seconds. I would have to left-click to keep on typing. Maddening.

I noticed that the color scheme for the areas around the edges of the windows windows would change every time it happened. It seemed like and easy way to see loss of focus without actually typing.

So, I started windows task manager and clicked on the processes tab. After watching for a little while, I could see that the Adobe desktop manager was coming off and on the list simultaneously with the loss of focus change of color.

I downloaded and re-installed the Adobe Creative Cloud desktop application. (Note: I could not uninstall it, so I just installed the download right over the existing one. There is a special program for uninstalling Creative Cloud if this doesn't work.) This cured my problem completely.

For those with Creative Cloud, this might be the program. For those without, watching the processing tab and the change of color around the edges of the windows with each loss of focus may help you find the culprit.

1

I used task manager to look for background processes, and Synaptics Touchpad was the culprit.

The 'driver' was on constantly, but another process by Synaptics was popping up every few seconds and causing the focus to be lost.

I uninstalled Synaptics and hey presto, no more losing focus!

1

In Regedit (Hold down Start Button+R, then type regedit), change the HKEY_CURRENT_USER\Control Panel\Desktop\ForegroundLockTimeout value from 0 to 30d40 . Save and restart the computer.

0

Check for a backup utility such as Gladinet or Nuance Cloud Connector. (Both use Gladinet's engine and this sort of problem was known to them in 2012 already.) They are running a windowless / task-less dll based within Explorer.exe.

0

My Samsung Galaxy S6 was in constant "Upgrading Android" and when connected through USB for charging, I've got lost focus problem every 10 seconds, but no explorer window popped up into front. I've changed usb port and selected to "Usb Charging" mode from phone, after that focus problem went away.

But constant "Upgrading Android" problem is still there and needs to be solved still.

0

I have the same problem. My case it was a Windows XP program that was run on a standard user account. It needed administrator elevated rights to run. So while it did run in the background, I did not see it, it frequently stole the focus of my current window (windows explorer, firefox, and other programs). It is very annoying. I used focus.exe by happy droid to identify the culprit. Also you can use Windows Focus Logger for the same purpose.

0

I too encountered same problem. Whenever i going to click on chrome or any window except task manager windows looses focus. I observed when we restart windows explore process from task manager. It works fine for some 5 to 8 seconds.after that it again loosen focus. We need to find culprit process from task manager. In my case it was macafee web advisor. I uninstalled it. Then works fine for me.

0

In case of my corporate ThinkPad laptop with Windows 10 it was Zoom (in Away mode) that captured focus periodically (every minute or so).

I established this by opening Task Manager (leaving it running as the foreground application), increasing update frequency to Highest, and sorting the apps by CPU usage (no filming was necessary, just watching).

0

For anyone else experiencing a problem of your window losing focus, or your text becoming selected text when you take a pause from typing, I had these issues for months and although it was annoying I learned to live with it... that was until I finally found the culprit! If you type in your Windows search bar "Event Viewer", then expand "Custom Views" and select "Administrative Events", there should be a bunch of errors displayed, these errors are what's causing the focus to be redirected. If you select one, under "General" it gives the details to the error that is occurring. I copy and pasted that error message in Google and found out my problem was with a Broadcom driver. Yours could be something similar or the same thing, either way the solution was found with that Google search. In my particular case, all I had to do was uninstall the Broadcom driver, and boom! Problem Solved!! I hope this helps someone that is having similar issues as I was banging my head against the keyboard for months trying to figure this one out! God bless!

1
  • Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.
    – Community Bot
    Jan 14, 2023 at 10:55
-1

The same problem I encountered. My laptop is bit old. I t has 2GB RAM and Window 7. After running for an hour this same thing happens everytime. I noticed this case arises when the laptop was overheating. Solution: Install a automatic RAM Cleaner software. Its been a month after installing automatic RAM cleaner and I never faced the problem again.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .