tags:

views:

161

answers:

7

I've been looking at the code in this tutorial, and I found that it uses My.Computer.Name to save settings that shouldn't roam between computers. It's entirely possible, however, for a user to have two identically named PCs. If they wanted to have the same username on each PC, for example, they may very well end up with two PCs named Username-PC.

What are some good methods of identifying different PCs? Do PCs have GUIDs associated with them, or should I look into pulling the serial number off of some hardware? I don't care if the identification persists through reinstallation of Windows.

(The tutorial I linked is in VB.Net, but I'm implementing it in C#)

A: 

I don't think it's possible to have two PC's with the same name on the same domain. Have you tried capturing the domain name?

user279521
I have 2 PCs on the same domain with the same name :-) I dual boot between xp and win 7...although haven't booted into xp fr over 2 weeks now
SQLMenace
@SQLMenace: Unless that have the same SID, the network still sees them as different boxes.
Steven Sudit
It is the same box..I had to do some fancy stuff to make it to the domain from both boxes
SQLMenace
A: 

Take a look here: http://stackoverflow.com/questions/1537908/getting-service-tag-from-dell-machine-using-net

You could snatch some unique data from the registry.

JonH
And when the registry changes...
Steven Sudit
Steven, these specific values are hardware specific.
JonH
@JonH: Hardware changes. Disc drives, CPU's, all of it. When it breaks, it's replaced.
Steven Sudit
+2  A: 

Each computer has a SID that's unique under normal circumstances.

Steven Sudit
A: 

One thing you can use is the MAC of any Network interface. You can also combine several sources of information. Like HDD Serial number, mac, processor type to calculate a hash from it.

schoetbi
The more sources you use, the more reliable it is. However, the more sources you use, the more vulnerable you are to false positives.
Steven Sudit
+6  A: 

Some good identifiers:

  • MAC Address: It's fairly easy to get at, and it's usually unique. However, it can be spoofed/changed rather easily, so it depends on how unique it needs to be.
  • CPU Serial Number: It's not available on lots of older systems, but it's there. Check out this MSDN page. It won't change, but it's bound to a computer.
  • HDD Serial Number: It's likely to not change, but can be a nuisance if the HD fails. Check out this MSDN page.
mattbasta
John MacIntyre
Careful: I've seen cases where the CPU (of a laptop) got toasted and had to be replaced. New CPU, new CPUID.
Steven Sudit
@Steven: Good point. Generally, though, I'd consider it one of the "most reliable" IDs on a system. CPU failure is relatively uncommon (compared to HD failure). It should also be noted that this number might get gummed up when you start dealing with virtualization.
mattbasta
Yes, virtualization sounds like a more likely reason for all sorts of failures, as compared to hardware changes.
Steven Sudit
A: 

If you are on windows HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\ CurrentVersion\ProductId is unique per machine/per windows install. where as in some of the other answers like the MAC address, Proc SN, and HD SN will stay the same between windows reinstalls/dual boot situations.

Scott Chamberlain
Is this the number used by Windows to detect when it's been installed onto a different machine?
Steven Sudit
@Steven Sudit, Yes, I believe this number is generated by a hash of several pieces of HW information, the windows serial key and a timestamp. When you activate windows they send the serial key and this code and store the code on their servers.
Scott Chamberlain
Here is a wiki page talking about how they are generated http://wiki.lunarsoft.net/wiki/Product_IDs
Scott Chamberlain
Well, the positive here is that anything capable of changing this product ID will also be a major pain to Windows itself. :-)
Steven Sudit
A: 

Use the network card's MAC address. It's supposed to be unique. It can be changed, though. It depends on how malicious you expect your users to be and how critical your application is.

Some sample code to do it:

public string GetMACAddress() {
    ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
    ManagementObjectCollection moc = mc.GetInstances();

    string MACAddress = String.Empty;

    foreach (ManagementObject mo in moc) {
        if (MACAddress == String.Empty) { // only return MAC Address from first card
            if ((bool)mo["IPEnabled"] == true) MACAddress = mo["MacAddress"].ToString();
        }
        mo.Dispose();
    }

    return MACAddress;
}
MicSim