我想获取硬盘序列号。我该怎么做?我尝试了两个代码,但没有得到
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>"); } }
在这个我没有得到任何唯一的序列号。第二个是
string drive = "C"; ManagementObject disk = new ManagementObject("win32_logicaldisk.deviceid=\"" + drive + ":\""); disk.Get(); Label3.Text = "VolumeSerialNumber="+ disk["VolumeSerialNumber"].ToString();
我在这里VolumeSerialNumber。但这不是唯一的。如果我格式化硬盘,这将会改变。我怎么能得到这个?