我试图用zoom.exe( psutil )杀死一个进程。但是,我得到了一个错误psutil.AccessDenied。我有所有的权限去做这件事,并且已经在另一台pc上进行了测试。
码
def kill_process(PROCNAME):
for proc in psutil.process_iter():
if proc.name() == PROCNAME:
proc.kill()
print(f'{PROCNAME} was succesfully killed')
time.sleep(3)溯源
Traceback (most recent call last):
File "C:\Users\Acer\AppData\Local\Programs\Python\Python38-32\lib\site-packages\psutil\_c
ret = self._cache[fun]
AttributeError: _cache
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Acer\AppData\Local\Programs\Python\Python38-32\lib\site-packages\psutil\_p
return fun(self, *args, **kwargs)
File "C:\Users\Acer\AppData\Local\Programs\Python\Python38-32\lib\site-packages\psutil\_c
return fun(self)
File "C:\Users\Acer\AppData\Local\Programs\Python\Python38-32\lib\site-packages\psutil\_p
exe = cext.proc_exe(self.pid)
PermissionError: [WinError 24] The program issued a command but the command length is incorrect.
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:/Users/Acer/Desktop/autozoom/autozoom.py", line 211, in <module>
kill_process('Zoom.exe')
File "c:/Users/Acer/Desktop/autozoom/autozoom.py", line 25, in kill_process
if proc.name() == PROCNAME:
File "C:\Users\Acer\AppData\Local\Programs\Python\Python38-32\lib\site-packages\psutil\__init__.py", line 630, in name
name = self._proc.name()
File "C:\Users\Acer\AppData\Local\Programs\Python\Python38-32\lib\site-packages\psutil\_pswindows.py", line 750, in name
return os.path.basename(self.exe())
File "C:\Users\Acer\AppData\Local\Programs\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=7868)发布于 2020-06-12 17:00:38
解决了此代码的问题:
def kill_process(PROCNAME):
for proc in psutil.process_iter():
try:
if proc.name().lower() == PROCNAME.lower():
proc.kill()
return True
except (psutil.NoSuchProcess, psutil.AccessDenied, psutil.ZombieProcess):
return Falsehttps://stackoverflow.com/questions/62334530
复制相似问题