Even you can read harddisk serial number,
size, partitions, free space and so on.
Now let's read the serial number of a harddisk in C# with ManagementClass WMI.
public static string HardDiskID()This static function will simple give us the volume serial numbers.
{
ManagementClass partionsClass = new ManagementClass("Win32_LogicalDisk");
ManagementObjectCollection partions = partionsClass.GetInstances();
string hdd = string.Empty;
foreach (ManagementObject partion in partions)
{
hdd = Convert.ToString(partion["VolumeSerialNumber"]);
if (hdd != string.Empty)
return hdd;
}
return hdd;
}
C# Read Harddisk Serial Number WMI ManagementClass.
2 comments:
Interesting, but this read the sn of the partition, not of the hd.
Good essay!
I tried to learn hard disk number but when I compare them I take COM error, but your code is working properly! (TURKEY)
Post a Comment