diff --git a/psutil/_psutil_windows.c b/psutil/_psutil_windows.c index 7ad8c9589..066a919af 100644 --- a/psutil/_psutil_windows.c +++ b/psutil/_psutil_windows.c @@ -573,13 +573,7 @@ psutil_proc_exe(PyObject *self, PyObject *args) { } if (GetProcessImageFileNameW(hProcess, &exe, MAX_PATH) == 0) { CloseHandle(hProcess); - if (GetLastError() == ERROR_INVALID_PARAMETER) { - // see https://github.com/giampaolo/psutil/issues/414 - AccessDenied(); - } - else { - PyErr_SetFromWindowsErr(0); - } + PyErr_SetFromWindowsErr(0); return NULL; } CloseHandle(hProcess); diff --git a/psutil/_pswindows.py b/psutil/_pswindows.py index 1a786f103..b540bdac2 100644 --- a/psutil/_pswindows.py +++ b/psutil/_pswindows.py @@ -245,6 +245,11 @@ def exe(self): # Note: os.path.exists(path) may return False even if the file # is there, see: # http://stackoverflow.com/questions/3112546/os-path-exists-lies + + # see https://github.com/giampaolo/psutil/issues/414 + # see https://github.com/giampaolo/psutil/issues/528 + if self.pid in (0, 4): + raise AccessDenied(self.pid, self._name) return _convert_raw_path(cext.proc_exe(self.pid)) @wrap_exceptions