Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / .NET SDK / January 2004

Tip: Looking for answers? Try searching our database.

how to get the MAC address by .net program if the OS is win98?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Cyrus - 08 Jan 2004 10:02 GMT
thz
Chris Taylor - 09 Jan 2004 12:27 GMT
Hi,

1) You can install WMI on 98 and use some thing like the GetMacAddresses
included in this post.

2) On 98 you can generate a GUID and extract the MAC address the MAC address
will be the least significant 6 bytes will be the MAC address ( Not
Recommended however ).
Contrary to popular belief, you can still use this on W2k, XP and W2k3, but
you must use UuidCreateSequential() to generate the GUID, this will require
interop. Again, just because you can do it does not mean you should.

3) If your network card has NetBIOS bound to it you can use the following
information to get the MAC Address
http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q118623. This will
again require some use of interop.

Of all the options I believe option 1 to be prefereable and mention the
others for completeness.

Hope this helps

Chris Taylor
http://dotnetjunkies.com/WebLog/chris.taylor/

   private static string[] GetMacAddresses()
   {
     System.Management.ManagementClass mc =
       new
System.Management.ManagementClass("Win32_NetworkAdapterConfiguration");

     ArrayList list = new ArrayList();
     foreach ( System.Management.ManagementObject mo in mc.GetInstances() )
     {
       if ( ((bool)mo["IPEnabled"]) == true )
         list.Add( mo["MACAddress"] );
     }

     if ( list.Count > 0 )
     {
       string[] macAddresses = new string[list.Count];
       list.CopyTo( macAddresses, 0 );

       return macAddresses;
     }

     return null;
   }

> thz
Danny Lesnik - 11 Jan 2004 06:11 GMT
but install win98 wmi sdk and .NET Framework

            System.Management.ManagementObjectSearcher query = null;
            System.Management.ManagementObjectCollection queryCollection = null;

            try
            {
                query = new System.Management.ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapterConfiguration") ;

                queryCollection = query.Get();

                foreach( System.Management.ManagementObject mo in queryCollection )
                {
                    if(mo["MacAddress"] != null)
                    {
                        Console.WriteLine(mo["MacAddress"].ToString());
                    }
                }
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex.Source);
                Console.WriteLine(ex.Message);
            }
Cyrus - 12 Jan 2004 02:41 GMT
why i got several mac address by this eg.?
how can i determind which mac address is the one in which my program is
running?
thz

> but install win98 wmi sdk and .NET Framework:
>
[quoted text clipped - 20 lines]
> Console.WriteLine(ex.Message);
> }
Cyrus - 12 Jan 2004 02:56 GMT
oh. i got the exact mac address by taylor's method
but i want to know more about that
what's mean by mo["IPEnabled"]?
any reference about that?
thz

> why i got several mac address by this eg.?
> how can i determind which mac address is the one in which my program is
[quoted text clipped - 26 lines]
> > Console.WriteLine(ex.Message);
> > }
Michael Bray - 14 Jan 2004 18:54 GMT
"Chris Taylor" <chris_taylor_za@hotmail.com> wrote in news:#XgLzvq1DHA.3216
@TK2MSFTNGP11.phx.gbl:

> Win32_NetworkAdapterConfiguration

How can I get a list of all of the WMI classes available, such as
"Win32_NetworkAdapterConfiguration"??

Thanks!

-mdb
Chris Taylor - 14 Jan 2004 21:02 GMT
Hi,

You can take a look at the WMI docs in the reference
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnanchor/html/a
nch_wmi.asp


There is also a see the WMI explorer at
http://msdn.microsoft.com/library/default.asp?url=/downloads/list/wmi.asp

Hope this helps
Signature

Chris Taylor
http://dotnetjunkies.com/WebLog/chris.taylor/

> "Chris Taylor" <chris_taylor_za@hotmail.com> wrote in news:#XgLzvq1DHA.3216
> @TK2MSFTNGP11.phx.gbl:
[quoted text clipped - 7 lines]
>
> -mdb
Michael Bray - 14 Jan 2004 22:57 GMT
"Chris Taylor" <chris_taylor_za@hotmail.com> wrote in news:eRwRJHu2DHA.2700
@tk2msftngp13.phx.gbl:

> http://msdn.microsoft.com/library/default.asp?url=/downloads/list/wmi.asp

I get "Sorry, we were unable to service your request.  As an option, you
may visit any of the pages below for information about Microsoft services
and products.".  Is this a temporary problem of the MS Website, or is it
some kind of restricted access?

Also, I was hoping there was a programmatic way to determine all of the WMI
classes available (so I can populate a dropdown, for example.)  Any
suggestions?

Also...   some of the WMI classes don't seem to be valid.  For example,
when I try to load Win32_PhysicalMedia, I get "Invalid Class" exception.  I
would think that class would be common...  why is this class not available?

-mdb

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.