2

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?

  • 2
    Are you sure that returned `windowName, t, p` are correct? Check if GetForegroundWindow doesn't return None. – Zuljin Dec 17 '11 at 11:13
  • 1
    (87, 'OpenProcess', 'The parameter is incorrect.)' error was caused by windowName being 0. But, the other error remains. This occurs only when I run a full-screen game. –  Dec 18 '11 at 04:32

1 Answers1

1

First of all do you need 0x0410 permissions (PROCESS_VM_READ+PROCESS_QUERY_INFORMATION)? Maybe obtaining PROCESS_QUERY_INFORMATION or PROCESS_QUERY_LIMITED_INFORMATION is enough for your needs? Check this MSDN page for permissions description http://msdn.microsoft.com/en-us/library/windows/desktop/ms684880(v=vs.85).aspx

If this still fail you can try add Debug permission using SeDebugPrivilege for your process and with them it should open any process you want. Check these links for more info:

Community
  • 1
  • 1
Zuljin
  • 2,612
  • 17
  • 14