Solved

WIreless Mac Address

Posted on 2010-09-06
7
1,705 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
  • 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

828 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