So, I'm trying to write a simple time tracker in python using the pywin32 module. It works fine most of the time, but in some cases it shows one of the following errors:
(5, 'OpenProcess', 'Access is Denied.')
(87, 'OpenProcess', 'The Parameter is incorrect.)'
The problems usually occur when minimizing a window or running a full screen application such as a game.
Running the script as an administrator does not help. This is how I'm trying to do it:
windowName = win32gui.GetForegroundWindow()
t, p = win32process.GetWindowThreadProcessId(windowName)
handle = win32api.OpenProcess(0x0410, False, p)
windowPath = win32process.GetModuleFileNameEx(handle, 0)
Any way to fix this?