I am trying to develop a registration algorithm in C#. I used MAC address of the client machine to generate the request code. The function is shown below. But in Windows 7, This function shows a NullRererenceException
in this line.
mac = mo["MACAddress"].ToString();
public string GetMACAddress()
{
string mac = null;
ManagementObjectSearcher mos = new ManagementObjectSearcher("select * from Win32_NetworkAdapterConfiguration");
foreach (ManagementObject mo in mos.Get())
{
mac = mo["MACAddress"].ToString();
break;
}
return mac;
}
What is the most reliable way to get MAC address, in Windows 7 and Windows 8, using C#, in order to develop an activation algorithm?