
Getting MAC Address in WIndows 98 and NT/2000/NT
This code works on 2000 and breaks on Windows98:
private static string GetMacAddress()
{
ManagementClass mc = new ManagementClass("Win32_NetworkAdapter");
foreach (ManagementObject mo in mc.GetInstances())
{
string macAddr = mo["MACAddress"] as string;
if ( macAddr != null && macAddr.Trim() != "" )
return macAddr;
}
// no NICs found
return "";
Quote:
}
************** Exception Text **************
System.TypeInitializationException: The type initializer for
"System.Management.ManagementBaseObject" threw an exception. --->
System.Runtime.InteropServices.COMException (0x80040154): COM object with
CLSID {674B6698-EE92-11D0-AD71-00C04FD8FDFF} is either not valid or not
registered.
at System.Management.ManagementBaseObject..cctor()
--- End of inner exception stack trace ---
at System.Management.ManagementBaseObject..ctor(IWbemClassObjectFreeThreaded
wbemObject)
at System.Management.ManagementObject..ctor(ManagementScope scope,
ManagementPath path, ObjectGetOptions options)
at System.Management.ManagementClass..ctor(ManagementScope scope,
ManagementPath path, ObjectGetOptions options)
at System.Management.ManagementClass..ctor(String path)