I use the code below:
Public string GetHardDiskID ()
{
//create ManagementObjectSearcher object
ManagementObjectSearcher searcher=new ManagementObjectSearcher (" SELECT * FROM Win32_PhysicalMedia ");
String harddiskID=null;//storage disk serial number
//call ManagementObjectSearcher class the Get method to Get the hard disk serial number
Foreach (ManagementObject mo in a searcher. The Get ())
{
If (mo/" SerialNumber "!=null)
{
HarddiskID=mo [r]. "from" the ToString (). The Trim ();//record the disk serial number
break;
}
}
If (harddiskID==null)
{
"Return" to obtain failure;
}
The else
{
Return harddiskID;
}
}
But in the process of actual use, found that win 10 in the event of a system is updated, the serial number will be change, this cannot be used for software licensing,
Could you tell me exactly how to obtain will never change the hard disk serial number? Thank you very much!
CodePudding user response:
Do you have more than one hard disk (solid, mechanical)So will "change"
Is, in fact, for the different hard disk serial number
Another is opened after the hyper - v for virtual device, this may also be different
The code itself no problem