11

How to uniquely identify computer (mainboard) using C#(.Net/Mono, local application)?

Edition. We can identify mainboard in .Net using something like this (see Get Unique System Identifiers in C#):

using System.Management;
...
ManagementObjectSearcher searcher = new ManagementObjectSearcher("select * from Win32_MotherboardDevice");
...

But unfortunately Mono does not support System.Management. How to do it under Mono for Linux? - I don't know :(

Community
  • 1
  • 1
macropas
  • 3,100
  • 3
  • 22
  • 25

5 Answers5

13

Write a function that takes a few unique hardware parameters as input and generates a hash out of them.

For example, Windows activation looks at the following hardware characteristics:

  • Display Adapter
  • SCSI Adapter
  • IDE Adapter (effectively the motherboard)
  • Network Adapter (NIC) and its MAC Address
  • RAM Amount Range (i.e., 0-64mb, 64-128mb, etc.)
  • Processor Type
  • Processor Serial Number
  • Hard Drive Device
  • Hard Drive Volume Serial Number (VSN)
  • CD-ROM / CD-RW / DVD-ROM

You can pick up a few of them to generate your unique computer identifier.

  • 5
    On the other hand you might want to keep them separate. That would allow for example to put in more memory, and you can allow changes as long as they happen one at a time. – Guffa Sep 13 '09 at 10:37
  • Good idea of generating a hash. – Matt Hanson Jan 15 '11 at 02:49
5

Please see: Get Unique System Identifiers in C#

Community
  • 1
  • 1
Mitch Wheat
  • 295,962
  • 43
  • 465
  • 541
4

You realistically have MotherboardID, CPUID, Disk Serial and MAC address, from experience none of them are 100%.

Our stats show

  • Disk serial Is missing 0.1 %
  • MAC Is missing 1.3 %
  • Motherboard ID Is missing 30 %
  • CPUID Is missing 99 %

0.04% of machines tested yielded no information, we couldn't even read the computer name. It maybe that these were some kind of virtual PC, HyperV or VMWare instance, or maybe just very locked down? In any case your design has to be able to cope with these cases.

Disk serial is the most reliable, but easy to change, mac can be changed and depending on the filtering applied when reading it can change if device drivers are added (hyperv, wireshark etc).

Motherboard and CPUID sometimes return values that are invalid "NONE", "AAAA..", "XXXX..." etc.

You should also note that these functions can be very slow to call (they may take a few seconds even on a fast PC), so it may be worth kicking them off on a background thread as early as possible, you ideally don't want to be blocking on them.

Sprotty
  • 5,676
  • 3
  • 33
  • 52
3

Try this:

http://carso-owen.blogspot.com/2007/02/how-to-get-my-motherboard-serial-number.html

Personally though, I'd go with hard drive serial number. If a mainboard dies and is replaced, that PC isn't valid any more. If the HDD drive is replaced, it doesn't matter too much because the software was on it.

Of course, on the other hand, if the HDD is just moved elsewhere, the information goes with it, so you might want to look at a combination of serial numbers, depending what you want it for.

Neil Barnwell
  • 41,080
  • 29
  • 148
  • 220
  • 2
    Both my mainboards and my operating systems tend to outlive my harddrives. At least so far. There are things called "backups" which enable an OS + software to survive dying HDDs :-) – Joey Sep 13 '09 at 10:46
  • To me the most unique thing that define a computer is the HDD. You take the hdd to another mainboard. Do you think your computer is the empty/with a new hdd mainboard or the one that has all your data, your OS etc. ? – Clement Herreman Sep 15 '09 at 12:04
2

How about the MAC address of the network card?

kenny
  • 21,522
  • 8
  • 49
  • 87
  • Maybe you are right. Simple common method for Windows and Linux using Mono is obtaining MAC address of the network card(s). – macropas Sep 15 '09 at 17:53
  • We use MAC address of the (first) network card (there may be more than one!), and with several hundred clients, this changes more often than we thought it would. We're currently looking for alternatives. – epalm Aug 15 '11 at 13:33
  • @Smith, thanks for the feedback. Please propose another solution that is as simple. – kenny Oct 16 '11 at 00:20
  • getting system information such as processorid using WMI is a start – Smith Oct 17 '11 at 21:23
  • @Smith that doesn't sound compatible with Mono since WMI is Windows specific. – kenny Oct 17 '11 at 23:39
  • well as you can see from the next answer, hardware information seems to be the best. There has to be a way to get these hardware information in other OS, do you know and api? – Smith Oct 18 '11 at 07:40