views:

1508

answers:

6

Hello,

what kind of 'unique' system identifiers can be easily obtained using C# (to hash and then uniquely identify a system)? I could just hash HDD size and things like that but I need to identify and distinguish computers that are all built by the same components so I can't go by that.

Appreciate hints, ideas, sample code!

+2  A: 

You can use WMI with C# to get quite a bit of information about hardware.

Hard Disk IDs and Ethernet MAC Address are two common unique identifiers used in system identification schemes. The MAC Address is, in theory, unique per network card.

Reed Copsey
In theory, but in practice there is no single unique id that could be used, given that there are tons and easily accessible, it's best to grab two or three and combine them to create a unique string (or hash)
Vinko Vrsalovic
Yes, I agree. That's why the "in theory" :)
Reed Copsey
+5  A: 

You can use the System.Management namespace to get all stuff related to the hardware, ProcessorId, MAC addresses, and a lot more info you can then hash together.

Take a look at this article:

http://www.codeproject.com/KB/system/GetHardwareInformation.aspx

Vinko Vrsalovic
To expand on the this and other answers a little bit:The MAC address of the network card(s) is going to be unique, even if the machines all use the same components. I would start with that.Second of all, you should be able to get motherboard and CPU serial numbers, as JP said. Those, plus the MAC address of physical NICs, should be easily enough to uniquely identify a machine. Just be aware that all of those can change if parts are replaced.
Jamie Penney
The MAC address of a network card can be set by software, so you cannot count on it being unique. On the other hand, I think main disk + mac address + processorId + motherboard could be a safe bet.
Vinko Vrsalovic
A: 

Presuming you are talking about Windows, then each Windows installation has a unique product id (which you can see when you view the properties of My Computer). I think this is stored in HKEY_LOCAL_MACHINE\Software\Microsoft\Windows. I take it you want more than that?

Dan Diplo
This looks kool.
Rahul2047
A: 

You could look into using GUID's

SwDevMan81
+1 The Microsoft implementation of GUIDs uses the MAC address and the current time, so they're pretty much a guarenteed way of creating identifiers that will be unique per computer.
Timothy Walters
+2  A: 

Network card MAC address:

foreach (NetworkInterface ni in NetworkInterface.GetAllNetworkInterfaces())
{
    // probably need to do some filtering on ni.NetworkInterfaceType here
    Console.WriteLine(ni.GetPhysicalAddress());
}
LukeH
+3  A: 

Here's a good start with WMI ...

// Win32_CPU will work too
var search = new ManagementObjectSearcher( "SELECT * FROM Win32_baseboard" );
var mobos = search.Get();

foreach (var m in mobos)
{
  var serial = m["SerialNumber"]; // ProcessorID if you use Win32_CPU
}

You can do that with many pieces of hardware and come up with a solution.

JP Alioto
I tried that ... but I see that these are days none of the serial nos are being maintained. Mother Board, Processor ... MAC is being changed by changing NIC ... what to choose?
Rahul2047