How to uniquely identify computer using C#?
Asked Answered
R

6

12

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 :(

Reputed answered 13/9, 2009 at 10:25 Comment(0)
S
2

How about the MAC address of the network card?

Sasin answered 15/9, 2009 at 12:1 Comment(6)
Maybe you are right. Simple common method for Windows and Linux using Mono is obtaining MAC address of the network card(s).Reputed
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.Boring
@Smith, thanks for the feedback. Please propose another solution that is as simple.Sasin
getting system information such as processorid using WMI is a startLayette
@Layette that doesn't sound compatible with Mono since WMI is Windows specific.Sasin
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?Layette
T
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.

Tomokotomorrow answered 13/9, 2009 at 10:29 Comment(2)
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.Commonage
Good idea of generating a hash.Giacopo
B
5

Please see: Get Unique System Identifiers in C#

Bandwagon answered 13/9, 2009 at 10:28 Comment(0)
O
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.

Orme answered 22/12, 2016 at 16:7 Comment(0)
A
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.

Anny answered 13/9, 2009 at 10:28 Comment(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 :-)Bin
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. ?Socket
S
2

How about the MAC address of the network card?

Sasin answered 15/9, 2009 at 12:1 Comment(6)
Maybe you are right. Simple common method for Windows and Linux using Mono is obtaining MAC address of the network card(s).Reputed
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.Boring
@Smith, thanks for the feedback. Please propose another solution that is as simple.Sasin
getting system information such as processorid using WMI is a startLayette
@Layette that doesn't sound compatible with Mono since WMI is Windows specific.Sasin
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?Layette
G
0

You can use DeviceId library. From here

string deviceId = new DeviceIdBuilder()
    .AddMachineName()
    .AddOsVersion()
    .OnWindows(windows => windows
        .AddProcessorId()
        .AddMotherboardSerialNumber()
        .AddSystemDriveSerialNumber())
    .ToString();
Geotaxis answered 19/4 at 18:50 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.