[Python] Getting 'psutil.AccessDenied (pid=6836)' error using psutil

Discussão em 'Python' iniciado por Stack, Fevereiro 16, 2025.

  1. Stack

    Stack Membro Participativo

    I want to check if a program is running or not, so I searched and I tried this , in this way:

    import psutil
    if "notepad.exe" in (p.name() for p in psutil.process_iter()):
    print('program is running')
    else:
    print('not running')


    but I get this error:

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):
    File "~/temp.py", line 2, in <module>
    if "notepad.exe" in (p.name() for p in psutil.process_iter()):
    File "~/temp.py", line 2, in <genexpr>
    if "notepad.exe" in (p.name() for p in psutil.process_iter()):
    File "~\Python\Python38-32\lib\site-packages\psutil\__init__.py", line 630, in name
    name = self._proc.name()
    File "~\Python\Python38-32\lib\site-packages\psutil\_pswindows.py", line 750, in name
    return os.path.basename(self.exe())
    File "~\Python\Python38-32\lib\site-packages\psutil\_pswindows.py", line 681, in wrapper
    raise convert_oserror(err, pid=self.pid, name=self._name)
    psutil.AccessDenied: psutil.AccessDenied (pid=6836)

    Process finished with exit code 1


    am I doing something wrong with this simple code? or is there another alternative way?

    EDIT: sorry, i forgot to mention im on windows, not linux, can u give me solutions for windows platform?

    Continue reading...

Compartilhe esta Página