Exception thrown while trying to get active window - WINDOWS
- [ x ] I am on the latest ActivityWatch version.
- [ x ] I have searched the issues of this repo and believe that this is not a duplicate.
- OS name and version: Windows 10 Pro 21H2
- ActivityWatch version: 0.12.1
-
- There is one that is similar, but it is for MacOS, and I checked through multiple bug reports and didn't seem to find something that applies. The fix seems to be use the latest binary (of course, I tried that).
Describe the bug
The AW window watcher seems to be throwing exceptions all the time. This is from the top of the log, but the main exception, below in the log, is replicated hundreds of times.
To Reproduce
Removed installed Activity watch components in both AppData/Local and AppData/Local/Programs. Reinstalled with both ADMIN and regular user authority. Checked the box to start AW. AW seems to start, but no window titles are reported, graphs don't display, etc. Checked logs for AW window watcher and can see the below logs
Expected behavior
The expected behavior is to see window titles both in the log and in the program.
Documentation
2022-10-10 14:40:43 [INFO ]: aw-watcher-window started (aw_watcher_window.main:62)
2022-10-10 14:40:45 [INFO ]: Connection to aw-server established by aw-watcher-window (aw_client.client:429)
2022-10-10 14:40:45 [ERROR]: Exception thrown while trying to get active window (aw_watcher_window.main:110)
Traceback (most recent call last):
File "aw_watcher_window\main.py", line 107, in heartbeat_loop
File "aw_watcher_window\lib.py", line 57, in get_current_window
File "aw_watcher_window\lib.py", line 40, in get_current_window_windows
File "aw_watcher_window\windows.py", line 26, in get_app_name
File "wmi.py", line 1072, in query
File "wmi.py", line 1072, in
Additional context
This is one of my favorite programs. So thank you so much for any help. I've used this program for a long time. All of sudden without any changes in my software setup, the Window Watcher seemed to be showing UNKNOWN for everything. I couldn't figure out a way to fix that. Now however, nothing seems to be working to get the window titles back.
Hi there! As you're new to this repo, please make sure you've used an appropriate issue template and searched for duplicates (it helps us focus on actual development!). We'd also like to suggest that you read our contribution guidelines and our code of conduct. Thanks a bunch for opening your first issue! 🙏
Why don't you export/backup settings and db and clean install complete activity watch package? Am also on same version of windows but unable to replicate your issue.
Hi,
I think I did. I uninstalled and then manually removed the folders. Tried reinstalling a couple times with regular credentials and then same process with admin. There is a chance I'm missing where they should be located though. So if you have exact locations to check I'll try again.
Thanks for looking at this issue with me.
On Tue, Oct 11, 2022, 12:31 AM Harsha Raghu @.***> wrote:
Why don't you export/backup settings and db and clean install complete activity watch package? Am also on same version of windows but unable to replicate your issue.
— Reply to this email directly, view it on GitHub https://github.com/ActivityWatch/activitywatch/issues/808#issuecomment-1274217719, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABGIRHYI6JP63SW5I4ZT5CTWCUJWBANCNFSM6AAAAAARBWXQ4A . You are receiving this because you authored the thread.Message ID: @.***>
I have also started getting this issue since updating to v0.12.1, so it's not just you.
Hmm, yikes. Not sure how to replicate this, need more info from users facing this issue what could be the culprit.
I did some searching and found a few occurrences of "error 0x80041010":
- https://learn.microsoft.com/en-us/answers/questions/665424/add-vpnconnection-script-works-on-co-worker39s-pc.html
- Unverified answer suggests it could have to do with wether you are running 64 or 32-bit Windows, so do you? (I assume 64bit, since I doubt it starts at all on 32bit systems, but I gotta ask)
- Unanswered cries for help
- https://stackoverflow.com/questions/73113222/python-wmi-hyper-v-getsummaryinformation-result-error
- https://github.com/tucnakomet1/Python-Who-Is-On-My-WiFi/issues/7
- Detailed but old article talking about it: https://www.virtuallyboring.com/microsoft-wmi-invalid-class-error-0x80041010/
However, most things seem to suggest this is a very generic error occurring in a bunch of different rare situations. Not very encouraging, so I hope someone better at Windows can chime in and help out!
Actually, sorry, I'm getting error 0x80041017 instead, but every other line in the error is the same. This is probably a separate thing.
Restarting the window watcher usually fixes it for it me and actually makes the missing window entries appear.
It looks like I got it before upgrading too, but it just didn't stop all entries from showing up thereafter before.
It looks like 0x80041010 means "Invalid WMI class" and 0x80041017 means "Invalid WMI query". Presumably, pid must not be getting set for me. I'm not sure what invalid WMI class could be caused by.
Not sure if related, but someone also had this issue: https://github.com/ActivityWatch/activitywatch/issues/804
I have also started getting this issue since updating to v0.12.1, so it's not just you.
What was the older version that was working for you ? You can take a backup of your browser settings and export database and can you install a olderversion of ActivityWatch(https://github.com/ActivityWatch/activitywatch/tags) to see if the older version(clean remove and clean install) is working now. This way we can know if it really is ActivityWatch version 0.12.1 update change issue and nothing on windows software has changed. Or If something on windows is changed without your knowledge.
Am insisting on this because https://github.com/ActivityWatch/aw-watcher-window/tree/master/aw_watcher_window windows.py hasnt changed from 6 years.
Hi All, I tried launching both v0.10.0 and v0.11.0 as both an ADMIN install and a regular user privileges'. I also tried installing them as either ALL USERS or just me. Those were the only set up files I have on this computer. In each case I get the same error as above, or slightly different format: 2022-10-15 16:40:43 [ERROR]: Exception thrown while trying to get active window: (-2147217392, 'OLE error 0x80041010', None, None) (aw_watcher_window.main:71).
I'm tempted to set up a dev install. Maybe that way I could provide more information. I worry, that this is just a "me" problem thought, so would hate for others to spend so much time on "MY" problem. Would debugging the python help?
Hi All, I tried launching both v0.10.0 and v0.11.0 as both an ADMIN install and a regular user privileges'. I also tried installing them as either ALL USERS or just me. Those were the only set up files I have on this computer. In each case I get the same error as above, or slightly different format: 2022-10-15 16:40:43 [ERROR]: Exception thrown while trying to get active window: (-2147217392, 'OLE error 0x80041010', None, None) (aw_watcher_window.main:71).
I'm tempted to set up a dev install. Maybe that way I could provide more information. I worry, that this is just a "me" problem thought, so would hate for others to spend so much time on "MY" problem. Would debugging the python help?
Then we can rule out that Error is because of ActivityWatch updates. You can try the Erik's suggestions. and even this (http://clintboessen.blogspot.com/2009/11/wmi-error-invalid-class-0x80041010-fix.html) This is a generic error not related to python but related to Windows WMI and its internal components, so i dont think setting up dev env will help much.
Hi All, I started the investigation anyway, just to see if I could get anywhere. I have a bit more data:
I saw, while going through the code that you referenced this bit of code: https://stackoverflow.com/questions/14394513/win32gui-get-the-current-active-application-name/14973422#14973422
So it turns out when I run the reference code, with a bit of the code from ActivityWatch, their code has an exception too, it just returns None. If I modify the example code slightly to get an exception, I get : Title: testwin.py - activitywatch - Visual Studio Code (-2147217392, 'OLE error 0x80041010', None, None) App: None
When I run the ActivityWatch code, the below happens:
Exception has occurred: com_error
(-2147217392, 'OLE error 0x80041010', None, None)
File "C:\Users\joshua\Downloads\aw-watcher-window-47b65c3673ee0203c911a269c1858a4ffbf971c4\aw-watcher-window-47b65c3673ee0203c911a269c1858a4ffbf971c4\aw_watcher_window\windows.py", line 26, in get_app_name
for p in c.query('SELECT Name FROM Win32_Process WHERE ProcessId = %s' % str(pid)):
File "C:\Users\joshua\Downloads\aw-watcher-window-47b65c3673ee0203c911a269c1858a4ffbf971c4\aw-watcher-window-47b65c3673ee0203c911a269c1858a4ffbf971c4\aw_watcher_window\windows.py", line 42, in

So it looks like the Error is in the query.
Also, failed to answer earlier info: This is a 64b machine, 16GB RAM, Core i7 10th gen. Windows 10 Pro.
Hi All, @ErikBjare suggestion worked. I followed the instructions here after seeing that the WMI services were invalid. I apologize for wasting everyone's time. The steps I took to resolve this are very similar to the article, but basically I executed:
- Open Admin CMD Prompt (Not powershell), that will drop you into Windows\System32\
- cd wbem
- dir /b *.mof *.mfl | findstr /v /i uninstall > moflist.txt & for /F %s in (moflist.txt) do mofcomp %s
- Open WMIMGMT.MSC
- Ensure the system connects to WMI management
Thanks to everyone who helped me: @ShootingKing-AM @mminer237 @ErikBjare
You can close the issue to mark it as solved. Also thanks for sharing the working solution :)
Wanted to confirm that 0.12.1 is working and it is. I previously had 0.11.0 installed.
Yay! Happy we could get to the bottom of this 😃