views:

1483

answers:

1

I need in my license Program use hardware id ,I tried use WMI,but it still slow .

I need Cpu,HDD,Motherboard info.

+15  A: 

For more details refer to this link

The following code will give you CPU ID:

namespace required System.Management

ManagementObjectCollection mbsList = null;
ManagementObjectSearcher mbs = new ManagementObjectSearcher("Select * From Win32_processor");
mbsList = mbs.Get();
string id="";
foreach (ManagementObject mo in mbsList)
{
   id = mo["ProcessorID"].ToString();
}

For Hard disk ID use the following

ManagementObject dsk = new ManagementObject(@"win32_logicaldisk.deviceid=""c:""");
dsk.Get();
string id = dsk["VolumeSerialNumber"].ToString();

Use the following for motherboard id:

ManagementObjectSearcher mos = new ManagementObjectSearcher("SELECT * FROM Win32_BaseBoard");
ManagementObjectCollection moc = mos.Get();
string serial="";
foreach (ManagementObject mo in moc)
{
     serial = (string)mo["SerialNumber"];
}

For more details refer this-link

HotTester
Good and extensive reply +1
Be warned, though, that these ids are not neccesarily unique, or even existant. The processorID just identifies the processor design, the VolumeSerialnumber can be changed by the user and there are mainboard manufacturers that do not set a Serialnumber.
Jens
The best way to generate a unique id is to make a id by combination of all of these id's i.e. cpu id, motherboard id and hard disk id.
HotTester
Thank you for your reply,But i think WMI still slow,do you have any other way with out WMI
guaike