我只需要使用 python 2.7 脚本阅读设备管理器中列出的所有信息。尤其是“IDE ATA/ATAPI 控制器”子类别下的信息。这需要检测 SATA 驱动器是处于 AHCI 还是 IDE 模式...
问问题
5348 次
2 回答
0
我的方法并不完美,但这对我来说是一个很好的解决方案,仅供您参考。通过 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')
于 2017-09-29T01:56:18.123 回答
0
一种简单的方法(在 Windows 上)是使用 Windows 设备管理器的 API。这里有一个 Python 绑定。安装包后,下面的代码就可以了:
from infi.devicemanager import DeviceManager
dm = DeviceManager()
dm.root.rescan()
devices = dm.all_devices
for device in devices:
print(device)
于 2021-12-05T08:25:06.973 回答