I want to get hard disk serial number. How I can I do that?
I tried with two code but I am not getting
StringCollection propNames = new StringCollection();
ManagementClass driveClass = new ManagementClass("Win32_DiskDrive");
PropertyDataCollection props = driveClass.Properties;
foreach (PropertyData driveProperty in props)
{
propNames.Add(driveProperty.Name);
}
int idx = 0;
ManagementObjectCollection drives = driveClass.GetInstances();
foreach (ManagementObject drv in drives)
{
Label2.Text+=(idx + 1);
foreach (string strProp in propNames)
{
//Label2.Text+=drv[strProp];
Response.Write(strProp + " = " + drv[strProp] + "</br>");
}
}
In this one I am not getting any Unique Serial number.
And Second one is
string drive = "C";
ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid="" + drive + ":"");
disk.Get();
Label3.Text = "VolumeSerialNumber="+ disk["VolumeSerialNumber"].ToString();
Here I am getting VolumeSerialNumber
. But it is not unique one. If I format the hard disk, this will change. How Can I get this?
Question&Answers:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…