views:

271

answers:

3

Hello.
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!

+1  A: 

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

Daniel Goldberg
Should be noted however that MACs can be changed from the NIC properties window for a lot of NICs, while a motherboard ID is a lot harder to change.
ErikHeemskerk
As far as I know you can change your mac address. And what to do if there are more than one netboard (or how should I name it)?
StuffHappens
That is correct. A motherboard ID is far more unique. However, if you do not require very strong uniqueness (i.e you can assume MACs don't change), acquiring a mac address is far easier.@Stuff, hash the addresses together? :)
Daniel Goldberg
+1  A: 

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?

Andy Sweetman
+1 for just generating a GUID :P
cwap
If he's trying to do this for a licencing mechanism, then SIDs and MAC addresses can be changed very easily so wouldn't be acceptable.
GenericTypeTea
+2  A: 

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

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.

GenericTypeTea
As I said before processor ID is not appropriate.
StuffHappens
@StuffHappens - Updated the answer.
GenericTypeTea
I see your point. I just doubt what will I get if there's a RAID and there are 2 different HDD with disk C on them.
StuffHappens
@StuffHappens - I'm assuming it'll probably end up returning the RAID controller ID or something. I'm sure Microsoft has considered that.
GenericTypeTea
@StuffHappens, just hash together multiple IDs of hard disks.
Daniel Goldberg