当前位置: 动力学知识库 > 问答 > 编程问答 >

system identification - Unique computer id

问题描述:

I'm looking for a way to get unique computer id. According to this post I can't use processor id for this purpose. Can I take motherboard id? What is the best way to identify the computer?

Thank you for your help!

网友答案:

Like you've said CPU Id wont be unique, however you can use it with another hardware identifier to create your own unique key.

Reference assembly System.Management

So, use this code to get the CPU ID:

string cpuInfo = string.Empty;
ManagementClass mc = new ManagementClass("win32_processor");
ManagementObjectCollection moc = mc.GetInstances();

foreach (ManagementObject mo in moc)
{
     cpuInfo = mo.Properties["processorID"].Value.ToString();
     break;
}

Then use this code to get the HD ID:

string drive = "C";
ManagementObject dsk = new ManagementObject(
    @"win32_logicaldisk.deviceid=""" + drive + @":""");
dsk.Get();
string volumeSerial = dsk["VolumeSerialNumber"].ToString();

Then, you can just combine these two serials to get a uniqueId for that machine:

string uniqueId = cpuInfo + volumeSerial;

Obviously, the more hardware components you get the IDs of, the greater the uniqueness becomes. However, the chances of the same machine having an identical CPU serial and Hard disk serial are already slim to none.

网友答案:

The motherboard ID is a pretty unique identifier. Another option is to use the network cards MAC address, which are pretty much unique.

网友答案:

MAC address of the network adapter? Security identifier (SID) of the windows OS install? (assuming it's windows you're dealing with) Could you just generate a GUID for each PC?

What exactly are you trying to achieve?

分享给朋友:
您可能感兴趣的文章:
随机阅读: