Python psutil on windows gives access denied

os: windows professional

I try to use psutil to get a list of processes and use them in cpu, I ran the script as an administrator, and it fails when it encounters the DymoPnpService.exe process, what could be the problem?

import psutil def process(): plist = psutil.get_process_list() plist = sorted(plist, key=lambda i: i.name) for i in plist: print i.name, i.get_cpu_percent() def main(): process() main() 

AcroRd32.exe 0.0 AcroRd32.exe 0.0 DymoPnpService.exe

 Traceback (most recent call last): File "C:\Users\krisdigitx\Documents\windowsutil.py", line 13, in <module> main() File "C:\Users\krisdigitx\Documents\windowsutil.py", line 10, in main process() File "C:\Users\krisdigitx\Documents\windowsutil.py", line 7, in process print i.name, i.get_cpu_percent() File "C:\Python27\lib\site-packages\psutil\__init__.py", line 330, in get_cpu_percent pt1 = self._platform_impl.get_cpu_times() File "C:\Python27\lib\site-packages\psutil\_psmswindows.py", line 125, in wrapper raise AccessDenied(self.pid, self._process_name) AccessDenied: (pid=1832, name='DymoPnpService.exe') 

more research:

strange, I can run the program from the Windows command line ... but it does not work in the style of python ide

+4
source share
2 answers

run this at the cmd.exe prompt: tasklist /FI "IMAGENAME eq DymoPnpService.exe" /V and check the "Username". If this is "NT AUTHORITY \ SYSTEM", it probably does not intentionally allow even the administrator account to get processor time,%, etc. Proc.

Take a copy of Process Explorer and find the path to the process and check the Security tab in the Settings menu with the right mouse button. To fix this, you can edit the owner or permissions of the DymoPnpService.exe executable file, but this can cause unexpected problems in Windows.


You can also simply continue the loop if the process does not allow you to get information about this:

 import psutil def process(): plist = psutil.get_process_list() plist = sorted(plist, key=lambda i: i.name) for i in plist: try: print i.name, i.get_cpu_percent() except AccessDenied: print "'%s' Process is not allowing us to view the CPU Usage!" % i.name def main(): process() main() 
+5
source

Starting with version 0.6.0, psutil on Windows will no longer call AccessDenied for different process methods (cpu_percent () among them): https://groups.google.com/forum/?fromgroups#!topic/psutil/oxAd0BuAzt0%5B1- 25% 5D

0
source

All Articles