Click here to Skip to main content
15,889,116 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
How to get The Serial of only HDD/SSD which windows are installed?

What I have tried:

I use this code to get all HDD/SSD in the device
private static void GetAllDiskDrives()
        {
            var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_DiskDrive");
            hdCollection.Clear();
            foreach (ManagementObject wmi_HD in searcher.Get())
            {
                HardDrive hd = new HardDrive();
                hd.Model = wmi_HD["Model"].ToString();
                hd.InterfaceType = wmi_HD["InterfaceType"].ToString();
                hd.Caption = wmi_HD["Caption"].ToString();

                hd.SerialNo = wmi_HD.GetPropertyValue("SerialNumber").ToString();//get the serailNumber of diskdrive

                hdCollection.Add(hd);
            }
        }

var HDDData = hdCollection.FirstOrDefault();
HDDSerial = HDDData == null ? "NULL" : HDDData.Model.ToString() + HDDData.SerialNo.ToString();

and the result like this :"ST1000LM024 HN-M101MBB S314J90FA57099"
(i have two HDD)

but what i want is to get only HDD/SSD which windows are installed?
Posted
Updated 17-Aug-22 4:04am

The problem is that physical disks are not what an OS boots from - they boot from a logical drive and a single physical disk can contain multiple logical drives. A logical drive doesn't have a serial number!

See here: Get Serial Number of Boot Drive and other info[^] - it's old, but it should still work.
 
Share this answer
 
Comments
Golden Basim 17-Aug-22 18:30pm    
I tried the mentioned solution but it show the " NTFS 3899563491" it seam differ the Drive Serial

as CDM
C:\Users\username>wmic diskdrive get model,serialnumber
Model                          SerialNumber
SanDisk Dual Drive USB Device  0101f6fcc1ab6ee14a44
ST1000LM024 HN-M101MBB         S314J90FA57099
WDC WDS120G2G0A-00JH30         184447803782
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900