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..223943511 100644 --- a/psutil/_pswindows.py +++ b/psutil/_pswindows.py @@ -245,6 +245,13 @@ 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 == 0: + raise AccessDenied(self.pid, self._name) + elif self.pid == 4: + raise AccessDenied(self.pid, self._name) return _convert_raw_path(cext.proc_exe(self.pid)) @wrap_exceptions