title: Python pywin32 Access Denied
body: <p>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: </p>
  
  <pre><code>(5, 'OpenProcess', 'Access is Denied.')
  (87, 'OpenProcess', 'The Parameter is incorrect.)'
  </code></pre>
  
  <p>The problems usually occur when minimizing a window or running a full screen application such as a game.</p>
  
  <p>Running the script as an administrator does not help. This is how I'm trying to do it:</p>
  
  <pre><code>windowName = win32gui.GetForegroundWindow()
  t, p = win32process.GetWindowThreadProcessId(windowName)
  handle = win32api.OpenProcess(0x0410, False, p) 
  windowPath = win32process.GetModuleFileNameEx(handle, 0)
  </code></pre>
  
  <p>Any way to fix this?</p>