Sunday, November 28, 2010

Unique Identifier for a computer

There are so many unique identifier. You may use Processor ID, any device Serial No. like Hard Drive Serial No. etc.

Please check the following code to read the ProcessorID:

public string GetMachineId()
    {
        string cpuInfo = String.Empty;
        ManagementClass managementClass = new ManagementClass("Win32_Processor");
        ManagementObjectCollection managementObjCol = managementClass.GetInstances();
        foreach (ManagementObject managementObj in managementObjCol)
        {
            if (cpuInfo == String.Empty)
            {
                cpuInfo = managementObj.Properties["ProcessorId"].Value.ToString();
            }
        }
        return cpuInfo;
    }


Note: You must add a reference of System.Management Assembly to use the above program.

No comments:

Post a Comment