Question

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!

Was it helpful?

Solution

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.

OTHER TIPS

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

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 NT\CurrentVersion:ProductId(REG_SZ). I take it you want more than that?

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.

Network card MAC address:

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

You could look into using GUID's

What is a GUID

For those of you who don't know, a GUID (pronounced goo'id - Globally unique identifier) is a 128-bit integer that can be used to uniquely identify something. You may store users or products in your database and you want somehow uniquely identify each row in the database. A common approach is to create a autoincrementing integer, another way would be to create a GUID for your products.

How to create a GUID in C#

The GUID method can be found in the System namespace. The GUID method System.Guid.NewGuid() initializes a new instance of the GUID class.

There are also a few overloads available for those of you who want the GUID formatted in a particular fashion.

The following live sample will output the GUID generated, the source code is also below.

Response.Write(@"<br>System.Guid.NewGuid().ToString() = " + System.Guid.NewGuid().ToString());
Response.Write(@"<br>System.Guid.NewGuid().ToString(""N"") = " + System.Guid.NewGuid().ToString("N"));
Response.Write(@"<br>System.Guid.NewGuid().ToString(""D"") = " + System.Guid.NewGuid().ToString("D"));
Response.Write(@"<br>System.Guid.NewGuid().ToString(""B"") = " + System.Guid.NewGuid().ToString("B"));
Response.Write(@"<br>System.Guid.NewGuid().ToString(""P"") = " + System.Guid.NewGuid().ToString("P"));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top