Solved

WIreless Mac Address

Posted on 2010-09-06
7
1,724 Views
Last Modified: 2012-05-10
When I run the following VBScript , I get the Mac Address for all the Local Area coonection & Wireless. How can I modify the script just to echo ONLY the Wireless one.

Thanks
Cheers

strComputer = (InputBox(" Computer name for MAC address", "Computer Name"))
If strComputer <> "" Then
strInput = True
End if
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery ("Select * From Win32_NetworkAdapterConfiguration Where IPEnabled = True")

For Each objItem in colItems
Wscript.Echo objItem.MACAddress
Next



0
Comment
Question by:Bianchi928
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 82

Expert Comment

by:hielo
ID: 33614176
try:
"Select * From Win32_NetworkAdapter WHERE NetConnectionID LIKE '%Wireless%'"

Resource:
http://msdn.microsoft.com/en-us/library/aa394595%28VS.85%29.aspx
0
 

Author Comment

by:Bianchi928
ID: 33614254
I've changed to and i get an error

Line 9
Char 1
Error 0x80041004
Code 80041004
Source (null)

Line 9 is the "For each


strComputer = (InputBox(" Computer name for MAC address", "Computer Name"))
If strComputer <> "" Then
strInput = True
End if
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery ("Select * From Win32_NetworkAdapter WHERE NetConnectionID LIKE '%Wireless%'")


For Each objItem in colItems
Wscript.Echo objItem.MACAddress
Next
 
0
 
LVL 8

Accepted Solution

by:
spinzr0 earned 125 total points
ID: 33614480
Here is some code I put together for someone last week.  Give it a shot.
On Error Resume Next

sAdminUserName = "username"
sAdminPassword = "password"
sWiFiQuery = "Select MACAddress from Win32_NetworkAdapterConfiguration WHERE Description Like '%WiFi%' OR Description Like '%Wireless%' OR Description Like '%AGN%'"

Set oComputerObject = CreateObject("WbemScripting.SWbemLocator")
oComputerObject.Security_.ImpersonationLevel = 3
oComputerObject.Security_.AuthenticationLevel = 0

sPC = InputBox(" Computer name for MAC address", "Computer Name")

If Ping(sPC) Then
    Err.Clear
    Set oWMI = oComputerObject.ConnectServer(sPC, "root\cimv2", sPC & "\" & sAdminUserName, sAdminPassword)
    If Err.Number <> 0 Then
        oOutputFile.WriteLine "Can't connect to " & sPC & ".  Please check username/password."
        Err.Clear
    Else
        Set cTemp = oWMI.ExecQuery(sWiFiQuery)
        For Each oItem In cTemp
            Msgbox oItem.MACAddress
            Exit For
        Next
        Set cTemp = Nothing
    End If
Else
    Msgbox sPC & " is not currently pingable."
End If
Set oWMI = Nothing

Set oComputerObject = Nothing
Wscript.Echo "Complete."

Function Ping(sHost)
    Dim oWMILocal, cPings, oPing, iPingResult

    Set oWMILocal = GetObject("winmgmts:\\.\root\cimv2")

    Set cPings = oWMILocal.ExecQuery("Select * from Win32_PingStatus " &_
        "Where Address = '" & sHost & "' AND timeout = 500")
    For Each oPing In cPings
        iPingResult = oPing.StatusCode
        If (iPingResult = 0) Then
            Ping = True
            Exit Function
        Else
            Ping = False
        End If
    Next
End Function

Open in new window

0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:Bianchi928
ID: 33614523
SPINZR0

ASKED FOR COMPUTER NAME , THEN  DIDN'T DISPLAY ANYTHING, WENT STRAIGHT TO DISPLAY "COMPLETE"
0
 

Author Comment

by:Bianchi928
ID: 33614547
SPINZR0

Oops..don't worry. I typed in the wrong admin password..

Thanks
0
 

Author Closing Comment

by:Bianchi928
ID: 33614548
Perfect
0
 
LVL 8

Expert Comment

by:spinzr0
ID: 33614584
Glad to hear it.  Also, if you change "oOutputFile.WriteLine" to "msgbox" then it will tell you that it failed.  Original code was outputing to a file.
0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Welcome back!  My apologies for taking so long to write part two of this series; it's been a long time coming!  As I promised in Part 1, this article will focus on how to locate those elusive AD properties that you are searching for.  Why is this us…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question