Getting HardDisk Serial Number

Firstly add a referance to the System.Management assembly using Project\Add Reference menu. Then use the "using System.Management" statement. And then the code gets the volume serial number for each driver on the computer.

ManagementObjectSearcher mos =
    new ManagementObjectSearcher("SELECT * FROM Win32_LogicalDisk");
ManagementObject mo;
foreach (int mo in mos.Get()) {
 Console.WriteLine("Name=" + mo("Name"));
 Console.WriteLine("VolumeSerialNumber=" + mo("VolumeSerialNumber"));
 Console.WriteLine();
}

If you want to get only C: drive infos, use the query below.

"SELECT * FROM Win32_LogicalDisk WHERE Name='C:'"

Ebook Download
View all
Learn
View all