Getting MAC Address in WIndows 98 and NT/2000/NT 
Author Message
 Getting MAC Address in WIndows 98 and NT/2000/NT

Is there a single method in C#  that can retreve machine MAC Address that
works on all supported .Net platforms?
-phil


Tue, 28 Dec 2004 01:22:43 GMT  
 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)


Tue, 28 Dec 2004 02:57:32 GMT  
 Getting MAC Address in WIndows 98 and NT/2000/NT
The best solution would not require WMI core to be installed on NT/98.


Quote:
> 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 "";
> }
> ************** 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

- Show quoted text -

Quote:
> 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)



Tue, 28 Dec 2004 03:16:25 GMT  
 Getting MAC Address in WIndows 98 and NT/2000/NT
Most/All the System.Management stuff uses WMI under the hood.

Win98 (and probably WinME as well) doesn't come with WMI installed
by default.

I think you can download it from Microsoft. Do a search for
WMI. I think it's the Redistributable you want, but I may be
wrong.

Be aware that not all WMI functions are available on Win98
(reading the EventLog is the first that comes to mind, Win9x
don't have an event log).

-c


Quote:
> 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 "";
> }
> ************** 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

- Show quoted text -

Quote:
> 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)



Tue, 28 Dec 2004 03:25:17 GMT  
 Getting MAC Address in WIndows 98 and NT/2000/NT
If you just need one MAC address (in case if you have multiple network cards
installed) from you machine, then Create a new Guid and extract the MAC
portion from that.

Guid = "Random Number" + Time + MAc Address

Thaks
Subbu


Quote:
> Is there a single method in C#  that can retreve machine MAC Address that
> works on all supported .Net platforms?
> -phil



Tue, 28 Dec 2004 04:16:43 GMT  
 Getting MAC Address in WIndows 98 and NT/2000/NT
System.Management requires WMI. So if you want to use
System.Management, you have to use WMI.

Barring that, you'll have to either use P/Invoke to get
the MAC natively somehow, or run ipconfig and parse the
output.

I believe that Win98 has ipconfig, but I may be wrong
(Win9x had winipcfg which was a Windows app rather than
cmd-line).

-c


Quote:
> The best solution would not require WMI core to be installed on NT/98.



> > 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 "";
> > }
> > ************** 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)



Tue, 28 Dec 2004 04:03:50 GMT  
 Getting MAC Address in WIndows 98 and NT/2000/NT
W2K doesn't use MAC addresses anymore for GUID's.

--
Sander Leer


Quote:
> If you just need one MAC address (in case if you have multiple network
cards
> installed) from you machine, then Create a new Guid and extract the MAC
> portion from that.

> Guid = "Random Number" + Time + MAc Address

> Thaks
> Subbu



> > Is there a single method in C#  that can retreve machine MAC Address
that
> > works on all supported .Net platforms?
> > -phil



Wed, 29 Dec 2004 06:33:16 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. IPC windows 95/98/NT/2000

2. Print Driver that calls my dialog for 98, NT, 2000

3. strcpy(x, x) works in NT/2000 but not 95/98

4. Reading registry values in 95/98 compared to NT/2000

5. Win 2000 built OCX won't load on a WIn NT or 98 system

6. supporting XP, 2000, NT, and 98

7. Program runs ONCE in 98/ME, works fine in Xp/NT/2000

8. MAC address under Windows 98

9. Q: E-mail address from 95/98/NT

10. E-mail address from 95/98/NT

11. DLL loading (Windows NT vs Windows 98)

12. Windows 98 Windows NT Visual C++ V1.52 and low level graphics

 

 
Powered by phpBB® Forum Software