Python Read the Device Manager Information

若如初见. 提交于 2020-01-05 05:58:50

问题


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...


回答1:


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


来源:https://stackoverflow.com/questions/41454473/python-read-the-device-manager-information

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!