Skip to content

Problems Getting MAC Adress

Bastian

Asked May 21, 2007, 11:59 AM EDT2 answers
Share
LinkedInX

Hi,
I need to check the MAC Adresses on my Computer.
I use the follwoing code and get alwys the follwing Error "error: cannot obtain value"

Dim strtemp As String

Dim bReturnValue As Boolean = True

Dim query As New SelectQuery("Win32_NetworkAdapter")

'ManagementObjectSearcher retrieves a collection of WMI objects based on

' the query.

Dim search As New ManagementObjectSearcher(query)

' Display each entry for Win32_bios

Dim info As ManagementObject

For Each info In search.Get()

strtemp = info("MacAddress").ToString()

If strtemp = MacAddress Then

bReturnValue = True

Exit For

End If

Next

I have no clue what the problem could be, Any good ideas?

Thanks

Bastian

2 Answers

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
    This code sample shows you the way to find out the MAC address of the system. Microsoft.Net provides System.Management namespace to perform this task. With the help of Visual Basic.Net code it's easy.

    Import the following namespace.

    Imports System.Management

    Declare following object variables.

    Dim objMOS As ManagementObjectSearcher

    Dim objMOC As Management.ManagementObjectCollection

    Dim objMO As Management.ManagementObject

    Execute the query.

    objMOS = New ManagementObjectSearcher("Select * From Win32_NetworkAdapter")

    objMOC = objMOS.Get

    Get MAC address from the query result.

    For Each objMO In objMOC

    MessageBox.Show(objMO("MACAddress"))

    Next

    Dispose object variables.

    objMOS.Dispose()

    objMOS = Nothing

    objMO.Dispose()

    objMO = Nothing

    0
  • 0
    Hi

    Thanks a lot, its funktioning.

    Best Regards

    Bastian
    0