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...
Asked
Active
Viewed 7,719 times
2
-
This is OS dependent so you should specify the Operating System(s) you care about. – rici Jan 04 '17 at 00:39
-
Windows 7, Windows 8, Windows 8.1, and Windows 10. – Erik343 Jan 04 '17 at 00:42
-
You can get the controller names using the [`Win32_IDEController`](https://msdn.microsoft.com/en-us/library/aa394155) WMI class, but I don't think that tells you whether it's currently operating in legacy ATA or SATA AHCI mode. You may need [`IOCTL_STORAGE_QUERY_PROPERTY`](https://msdn.microsoft.com/en-us/library/ff800830) to query the `StorageAdapterProperty` for the [`BusType`](https://msdn.microsoft.com/en-us/library/ff800833), i.e. `BusTypeAta` vs `BusTypeSata`. – Eryk Sun Jan 04 '17 at 12:26
2 Answers
1
One easy way (on Windows) is to use Windows Device Manager's API. There is a Python binding here. After installing the package, the code bellow will do fine:
from infi.devicemanager import DeviceManager
dm = DeviceManager()
dm.root.rescan()
devices = dm.all_devices
for device in devices:
print(device)

Parsa
- 53
- 7
0
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')

kyc1109
- 151
- 1
- 7
-
didn't work for me : ( , @ethan : good call - but also didn't work - " Python 3 support is experimental at this stage." – Dan Erez Jul 19 '18 at 14:24
-
Hi Dan You can try "devcon status *" in command line of windows. the devcon is MS's tool you can check it by help (devcon -h or -help) – kyc1109 Dec 20 '18 at 03:02