【问题标题】:Python Read the Device Manager InformationPython 读取设备管理器信息
【发布时间】:2017-05-18 04:37:00
【问题描述】:

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

【问题讨论】:

  • 这取决于操作系统,因此您应该指定您关心的操作系统。
  • Windows 7、Windows 8、Windows 8.1 和 Windows 10。
  • 您可以使用Win32_IDEController WMI 类获取控制器名称,但我认为这不能告诉您它当前是在旧版 ATA 还是 SATA AHCI 模式下运行。您可能需要IOCTL_STORAGE_QUERY_PROPERTY 来查询StorageAdapterProperty 中的BusType,即BusTypeAtaBusTypeSata

标签: python windows device-manager


【解决方案1】:

我的方法并不完美,但到目前为止对我来说这是一个很好的解决方案,仅供您参考。通过WDK(Windows Dev... Kit)中的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')   

【讨论】:

  • 对我不起作用 : ( , @ethan : 很好的调用 - 但也不起作用 - “Python 3 支持在这个阶段是实验性的。”
  • Hi Dan 您可以在 Windows 命令行中尝试“devcon status *”。 devcon 是 MS 的工具,你可以通过帮助(devcon -h 或 -help)查看它
【解决方案2】:

一种简单的方法(在 Windows 上)是使用 Windows 设备管理器的 API。有一个 Python 绑定 here。 安装包后,下面的代码就可以了:

from infi.devicemanager import DeviceManager
dm = DeviceManager()
dm.root.rescan()
devices = dm.all_devices
for device in devices:
    print(device)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-01-14
    • 2013-02-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-09
    • 1970-01-01
    相关资源
    最近更新 更多