Determine type of disk on Windows with Python

2024/11/15 8:59:19

I want to list all of my disk and can be able to know its type: "SATA" "NVME" "M.2" or "PCI" on Windows computer.

I made some research with wmi and I get the interface (SCSI or IDE):

c = wmi.WMI()
for disk in c.Win32_DiskDrive():print(disk.InterfaceType)

But I don't get the type of the disk. Maybe with the interface I can get the type of my disk ?

Do you have any idea ?

Thx

Answer

Query the MSFT_PhysicalDisk class if you insist upon wmi:

import wmi
ws = wmi.WMI(namespace='root/Microsoft/Windows/Storage')
for d in ws.MSFT_PhysicalDisk():print(d.BusType, d.MediaType, d.Model)

Sample ouput

 7 3 Elements 1078
11 4 KINGSTON model
11 3 WDC another model

MediaType enumeration:

Value   Meaning
0       Unspecified
3       HDD
4       SSD
5       SCM

Newest BusType enumeration (from WMI Explorer 2.0.0.2):

Value Text                Meaning
----- ----                -------
0     Unknown             The bus type is unknown.
1     SCSI                SCSI
2     ATAPI               ATAPI
3     ATA                 ATA
4     1394                IEEE 1394
5     SSA                 SSA
6     Fibre Channel       Fibre Channel
7     USB                 USB
8     RAID                RAID
9     ISCSI               iSCSI
10    SAS                 Serial Attached SCSI (SAS)
11    SATA                Serial ATA (SATA)
12    SD                  Secure Digital (SD)
13    MMC                 Multimedia Card (MMC)
14    MAX                 This value is reserved for system use.
15    File Backed Virtual File-Backed Virtual
16    Storage Spaces      Storage Spaces
17    NVMe                NVME
18    SCM                 SCM
19    UFS                 UFS
20    reserved            Microsoft reserved
https://en.xdnf.cn/q/120470.html

Related Q&A

How to get a list the visible vertices and segments of a mesh

I work on pose estimation of a 3d objects. I am using CAD model of that object to generate all the possible hypothesis of its pose. I am using pyopengl to render the view of the object from a specific…

Python function calls the wrong method/target

The following program simulates a traffic light system with some buttons. The buttons appear correctly, but if Im trying to call the method to create/change the LEDs, it ends up in the wrong method. He…

How to make a triangle of xs in python?

How would I write a function that produces a triangle like this:xxxxxxxxxx xxxxxLets say the function is def triangle(n), the bottom row would have n amount of xsAll I know how to do is make a box:n = …

Pip freeze --local

I am following a video tutorial and that guy did this:$ pip freeze --local > requirement.txt $ cat requirement.txtthis is to export all these packages with their versions in another project, but how…

How to optimize this Pandas code to run faster

I have this code to create a swarmplot from data from a DataFrame:df = pd.DataFrame({"Refined__Some_ID":some_id_list,"Refined_Age":age_list,"Name":name_list …

i was creating a REST api using flask and while i was about to test it on postman I saw that error

File "c:\Users\kally\rest\code\app.py", line 3, in <module>from flask_jwt import JWTFile "C:\Users\kally\AppData\Roaming\Python\Python310\site-packages\flask_jwt\__init__.py",…

Web scrape get drop-down menu data python

I am trying to get a list of all countries in the webpage https://www.nexmo.com/products/sms. I see the list is displayed in the drop-down. After inspecting the page, I tried the following code but I m…

TypeError(unsupported operand type(s) for ** or pow(): str and int,)

import mathA = input("Enter Wright in KG PLease :") B = input("Enter Height in Meters Please :")while (any(x.isalpha() for x in A)):print("No Letters Please")A = input(&qu…

How can I do assignment in a List Comprehension? [duplicate]

This question already has answers here:How can I do assignments in a list comprehension?(8 answers)Closed 1 year ago.Generally, whenever I do a for loop in python, I try to convert it into a list comp…

KeyError: column_name

I am writing a python code, it should read the values of columns but I am getting the KeyError: column_name error. Can anyone please tell me how to fix this issue. import numpy as np from sklearn.clust…