Python读取设备管理器信息 [英] Python Read the Device Manager Information

查看:84
本文介绍了Python读取设备管理器信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只需要使用 python 2.7 脚本阅读设备管理器中列出的所有信息.特别是IDE ATA/ATAPI 控制器"子类别下的信息.这需要检测SATA驱动器是在AHCI还是IDE模式下...

I just need to read all of the information that is listed in Device Manager with a python 2.7 script. Especially the information under 'IDE ATA/ATAPI controllers' subcategory. This is needed to detect whether the SATA drives are under AHCI or IDE mode...

推荐答案

我的方法并不完美,但目前对我来说是一个很好的解决方案,仅供大家参考.通过WDK(Windows Dev ... Kit)中的devcon.exe,以及我的代码如下.

My way is not perfect, but that is good solution so far for me, just for you reference. Through the devcon.exe which is in WDK(Windows Dev... Kit), and my code as below.

try:
    output = subprocess.Popen(["devcon","status","*"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)    #useing comma "," not space " " in Popen[]. replace the key word "*" to what you want to search.
    stdout, stderr = output.communicate()
    print "output: \n", output
    print "stdout: \n", stdout  # output here if ok. 
    print "stderr: \n", stderr  # output if no arg     
except subprocess.CalledProcessError:
    print('Exception handled')   

这篇关于Python读取设备管理器信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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