Windows 上的 python psutil 拒绝访问 [英] python psutil on windows gives access denied

查看:50
本文介绍了Windows 上的 python psutil 拒绝访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

操作系统:Windows 专业版

os: windows professional

我正在尝试使用 psutil 获取进程列表及其 CPU 使用情况,我以管理员身份运行脚本,但在遇到进程 DymoPnpService.exe 时失败,可能是什么问题?

i am trying to use psutil to get a list of processes and their cpu usage, i ran the script as administrator and it fails when it encounters process DymoPnpService.exe, what could be the issue?

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.0AcroRd32.exe 0.0DymoPnpService.exe

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')

更多研究:

奇怪的是,我可以从 windows 命令提示符运行该程序……但它在 python ide 中失败

strange i can run the program from the windows command prompt...but it fails in the python ide

推荐答案

在 cmd.exe 提示符下运行:tasklist/FI "IMAGENAME eq DymoPnpService.exe"/V 并检查User姓名".如果它是NT AUTHORITY\SYSTEM",那么它可能是故意不允许甚至管理员帐户获取 proc 的 cpu 时间、% 等.

run this in a cmd.exe prompt: tasklist /FI "IMAGENAME eq DymoPnpService.exe" /V and check the "User Name". If it is "NT AUTHORITY\SYSTEM" then it is probably intentionally not allowing even an Administrator account to get cpu times, %, etc of the proc.

获取 Process Explorer 的副本并找到进程的路径并检查首选项的安全选项卡右键菜单选项.要修复您可能可以编辑 DymoPnpService.exe 可执行文件的所有者或权限,但这可能会导致 Windows 中出现意外问题.

Grab a copy of Process Explorer and find the path of the process and check the Security Tab of the Preferences right click menu option. To fix you may be able to edit the Owner or Permissions of the DymoPnpService.exe executable but this could cause unexpected issues in Windows.

如果过程不允许您获取有关它的详细信息,您也可以继续循环:

You can also just continue the loop if the process doesn't allow you to get details about it:

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()

这篇关于Windows 上的 python psutil 拒绝访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆