I'm using the following code to retrieve the disk serial number of my hard
disk, but have nagging doubts as to whether it'll work on other machines.
Does anyone have experience of doing this who can advise whether I'm on
relatively safe ground here:
using System.Management;
....
private string GetDiskSerial()
{
string strSerial = "";
SelectQuery selQuery = new SelectQuery("SELECT * FROM
WIN32_DiskDrive");
ManagementObjectSearcher searchResult = new
ManagementObjectSearcher(selQuery);
foreach (ManagementObject item in searchResult.Get())
{
if (item["Signature"] != null)
{
strSerial = item["Signature"].ToString();
break;
}
}
return strSerial;
}
What I'm not sure of is the order in which disks are presented, so what
happens if there is more than one physical disk drive and what happens if
this is a diskless workstation.
I know I get the right result on my machine as the value returned matches
the one I see in the WMI browser.
Thanks
Steve