+ Reply to Thread
Results 1 to 2 of 2

Thread: Retrieve MAC Address

  1. #1

    Retrieve MAC Address

    I want to Retrieve the MAC Address of a computer using VisualBasic Scripting .
    Can you help me how to figure that ?

  2. #2
    Junior Member
    Join Date
    Jan 2012
    Posts
    40
    Here is the proper code to do that :
    Code:
    intCount = 0
     strMAC   = ""
     ' We're interested in MAC addresses of physical adapters only
     strQuery = "SELECT * FROM Win32_NetworkAdapter WHERE NetConnectionID > ''"
    
     Set objWMIService = GetObject( "winmgmts://./root/CIMV2" )
     Set colItems      = objWMIService.ExecQuery( strQuery, "WQL", 48 )
    
     For Each objItem In colItems
         If InStr( strMAC, objItem.MACAddress ) = 0 Then
             strMAC   = strMAC & "," & objItem.MACAddress
             intCount = intCount + 1
         End If
     Next
    
     ' Remove leading comma
     If intCount > 0 Then strMAC = Mid( strMAC, 2 )
    
     Select Case intCount
         Case 0
             WScript.Echo "No MAC Addresses were found"
         Case 1
             WScript.Echo "MAC Address: " & strMAC
         Case Else
             WScript.Echo "MAC Addresses: " & strMAC
     End Select

+ Reply to Thread

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts