Solved

WIreless Mac Address

Posted on 2010-09-06
7
1,679 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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 

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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
Well hello again!  Glad to see you've made it this far without giving up.  In this, the fourth installment of my popular series, I'm going to cover functions and subroutines, what they are, and why they are useful.  Just in case you stumbled onto th…
This video discusses moving either the default database or any database to a new volume.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

706 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now