Python读取设备管理器信息

Python读取设备管理器信息,python,windows,device-manager,Python,Windows,Device Manager,我只需要用Python2.7脚本读取设备管理器中列出的所有信息。尤其是“IDE ATA/ATAPI控制器”子类别下的信息。这是检测SATA驱动器是否处于AHCI或IDE模式所必需的 我的方法并不完美,但到目前为止,这是一个很好的解决方案,仅供参考。通过WDK(Windows开发…工具包)中的devcon.exe,我的代码如下 try: output = subprocess.Popen(["devcon","status","*"], stdout=subprocess.PIPE, st

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


我的方法并不完美,但到目前为止,这是一个很好的解决方案,仅供参考。通过WDK(Windows开发…工具包)中的devcon.exe,我的代码如下

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

我的方法并不完美,但到目前为止,这是一个很好的解决方案,仅供参考。通过WDK(Windows开发…工具包)中的devcon.exe,我的代码如下

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

这取决于操作系统,因此您应该指定您关心的操作系统。Windows 7、Windows 8、Windows 8.1和Windows 10。您可以使用WMI类获取控制器名称,但我认为这不会告诉您它当前是在传统ATA模式还是SATA AHCI模式下运行。您可能需要查询的
StorageAdapterProperty
,即
BusTypeAta
vs
BusTypeAta
。这取决于操作系统,因此您应该指定您关心的操作系统。Windows 7、Windows 8、Windows 8.1和Windows 10。您可以使用WMI类获取控制器名称,但我认为这并不能告诉您它目前是在传统ATA模式还是SATA AHCI模式下运行。您可能需要查询
StorageAdapterProperty
以获取,即
BusTypeAta
vs
BusTypeAta
。对我不起作用:(,@ethan:good call-但也不起作用-“Python 3支持目前处于试验阶段。”您好,您可以尝试“devcon status*”在windows的命令行中。devcon是MS的工具,您可以通过帮助检查它(devcon-h或-help)对我不起作用:(,@ethan:good call-但也不起作用-“Python 3支持在现阶段处于试验阶段”。您好,您可以在windows的命令行中尝试“devcon status*”。devcon是MS的工具,您可以通过帮助检查它(devcon-h或-help)