Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Windows 10 22H2] psutil.process_iter() results in PermissionError: [WinError 5] Access denied: '(originated from OpenProcess)' #2294

Open
shinrax2 opened this issue Aug 14, 2023 · 0 comments

Comments

@shinrax2
Copy link

shinrax2 commented Aug 14, 2023

Summary

  • OS: { Windows 10 22H2 64bit }
  • Architecture: { 64bit }
  • Psutil version: { Name: psutil
    Version: 5.9.6 (from git)
    Summary: Cross-platform lib for process and system monitoring in Python.
    Home-page: https://github.com/giampaolo/psutil
    Author: Giampaolo Rodola
    Author-email: g.rodola@gmail.com
    License: BSD-3-Clause
    Location: C:\Users\shinrax2\AppData\Roaming\Python\Python311\site-packages
    Requires:
    Required-by: } also tried 5.9.5 from pypi
  • Python version: { Python 3.11.4 64bit, installed via pyenv-win }
  • Type: { core }

Description

Traceback (most recent call last):
  File "C:\Users\shinrax2\AppData\Roaming\Python\Python311\site-packages\psutil\_pswindows.py", line 797, in cmdline
    ret = cext.proc_cmdline(self.pid, use_peb=True)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
PermissionError: [WinError 5] Zugriff verweigert: '(originated from OpenProcess)'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\shinrax2\AppData\Roaming\Python\Python311\site-packages\psutil_pswindows.py", line 696, in wrapper
return fun(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\shinrax2\AppData\Roaming\Python\Python311\site-packages\psutil_pswindows.py", line 712, in wrapper
return fun(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\shinrax2\AppData\Roaming\Python\Python311\site-packages\psutil_pswindows.py", line 800, in cmdline
ret = cext.proc_cmdline(self.pid, use_peb=False)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
PermissionError: [WinError 5] Zugriff verweigert: '(originated from OpenProcess)'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "C:\Users\shinrax2\Documents\GitHub\PS3GameUpdateDownloader\dist\PS3GameUpdateDownloaderDebug\updater.py", line 23, in
utils.waitForMainAppExit()
File "C:\Users\shinrax2\Documents\GitHub\PS3GameUpdateDownloader\dist\PS3GameUpdateDownloaderDebug\utils.py", line 385, in waitForMainAppExit
if exename in p.name().lower() or exename in (' '.join(p.cmdline()).lower()):
^^^^^^^^^^^
File "C:\Users\shinrax2\AppData\Roaming\Python\Python311\site-packages\psutil_init_.py", line 705, in cmdline
return self._proc.cmdline()
^^^^^^^^^^^^^^^^^^^^
File "C:\Users\shinrax2\AppData\Roaming\Python\Python311\site-packages\psutil_pswindows.py", line 698, in wrapper
raise convert_oserror(err, pid=self.pid, name=self._name)
psutil.AccessDenied: (pid=148, name='Registry')

Traceback
import psutil
def waitForMainAppExit():
    exename = (getExecutableBasename()+getExecutableSuffix()).lower()
    print(f"looking for {exename}")
    pid = None
    sleep_interval = 0.05
    for p in psutil.process_iter(attrs=["pid", "name"]):
        if exename in p.name().lower() or exename in (' '.join(p.cmdline()).lower()):
            pid = p.pid()
            print(f"found {exename} with pid: {pid}")
    if pid is not None:
        print(f"waiting for {exename} with interval of {sleep_interval}s")
        while psutil.pid_exists(pid) == True:
            time.sleep(sleep_interval)
utils.waitForMainAppExit() (reproduction code)

Additionally i tried running the code as administrator but that didn't change anything.
If anymore info is required please @ me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant