Python读取设备管理器信息

2024-05-16 15:27:02 发布

您现在位置:Python中文网/ 问答频道 /正文

我只需要用python2.7脚本阅读设备管理器中列出的所有信息。尤其是“IDEATA/ATAPI控制器”子类别下的信息。这是用来检测SATA驱动器是否处于AHCI或IDE模式。。。在

Device Manager


Tags: 脚本信息管理器模式控制器ide类别驱动器
1条回答
网友
1楼 · 发布于 2024-05-16 15:27:02

我的方法并不完美,但这对我来说是一个很好的解决方案,仅供你参考。通过devcon.exe在WDK(Windows开发。。。Kit),我的代码如下。在

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

相关问题 更多 >