C# .NET - Unique PC id's

Asked By stefan on 05-Sep-11 08:24 AM
Hi All
I am trying to get a unique id number from a pc.
I have done some research and i see ppl say getting the id of the CPU is not recomended. How can i get a Unique ID from a pc using code that will work on all windows formats?

Thanks in advance
Stefan
dipa ahuja replied to stefan on 05-Sep-11 08:29 AM
ManagementClass oMClass = new ManagementClass ("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection colMObj = oMCLass.GetInstances();
foreach(ManagementObject objMO in colMObj)
   
Console.WriteLine(objMO["MacAddress"].ToString());

also check this:
http://www.eggheadcafe.com/articles/20021019.asp
Reena Jain replied to stefan on 05-Sep-11 08:34 AM

Hi,

You need to use WMI check MSDN at this link:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmisdk/wmi/win32_motherboarddevice.asp

using System.Management;
 
//Connection credentials to the remote computer - not needed if the logged
in account has access
ConnectionOptions oConn = new ConnectionOptions();
oConn.Username = "Administrator";
oConn.Password = "";
 
System.Management.ManagementScope oMs = new
System.Management.ManagementScope(\\MachineID, oConn);
 
System.Management.ObjectQuery oQuery = new
System.Management.ObjectQuery("select SerialNumber from Win32_BaseBoard");
 
ManagementObjectSearcher oSearcher = new
ManagementObjectSearcher(oMs,oQuery);
 
ManagementObjectCollection oReturnCollection = oSearcher.Get();
 
foreach( ManagementObject oReturn in oReturnCollection )
{
Console.WriteLine("Serial Number : " +
oReturn["SerialNumber"].ToString());
}
stefan replied to dipa ahuja on 05-Sep-11 09:20 AM
Thanks for the help
That link Helped alot