Click here to Skip to main content
15,891,629 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi,
i try to get Serial no of the primary Hard Disk (OS installation disk) using C# to identify the Customer PC.

What I have tried:

i tried this code but the issue that when i inserted any Flash disk or another temporary disk the serial changed , the below code get the flash disk serial not the primary hard disk . so how to update this code to get only the Primary Hard disk serial (that contains Windows OS installations).

 public static List<HardDrive> hdCollection = new List<HardDrive>();
        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);
            }
        }
        public class HardDrive
        {
            public string Model { get; set; }
            public string InterfaceType { get; set; }
            public string Caption { get; set; }
            public string SerialNo { get; set; }
        }
public static string getUniqueDeviceID()
        {
            GetAllDiskDrives();
            var HDDData = hdCollection.FirstOrDefault();
            string HDDSerial = HDDData.Model + HDDData.SerialNo;
            string Combine = CPU_Serial + MotherBoardID + HDDSerial;
            string hash = ConvertTextToHash(Combine);
            return hash;
        }
Posted
Updated 9-Jan-20 13:55pm

You already asked this back in October.

How to find unique ID/code (can not be changed) for each device ?[^]
 
Share this answer
 
Comments
Golden Basim 10-Jan-20 11:28am    
i asked to get HDD serial ,but after i tried it a get this issue now i need to get the unique serial for the primary Hard driver that contains (windows OS)
Do you have to get it via C#? Alternatively you can download and run Speccy by Piriform. It's free. It will tell you whatever you need to know about your system - hardware and software.
 
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