Sign in to follow this  
Followers 0
JefFZ6

Wireless Configuration Script

11 posts in this topic

Our WiFi group is now requiring PEAP authentication to access our on campus WiFi network. In Vista and Mac OS this is a non-issue but on XP it's a somewhat lengthy process to configure the SSID in your preferred networks list. Most users make a mistake along the way and therefore cannot access the network.

So, I wrote an AutoIt script that works quite well. The only unreliable part is the way I'm "locating" their WiFi adapter and getting into the properties for that connection. I'm sending keys using ControlSend at the end to actually get the properties and sometimes that fails. Not sure why it fails there but it's at random (Maybe 1/20 times). When it fails I'll hear windows beep at me because of invalid keys being pressed and then it errors out.

Here's how I do it now:

;Open the Network Connections control panel

Run ("control.exe ncpa.cpl")

If 0 = WinWait ("Network Connections", "", 25) then

MsgBox (16, "Error", "Unable to automatically configure your Network Connection")

Exit

EndIf

;Find out how many Network Connection items are listed

$ItemCount = ControlListView("Network Connections", "", 1, "GetItemCount")

;Subrtract 1 from the Item Count because the index starts at 0

$ItemIndex = $ItemCount - 1

;Check each Network Connection item to see if it's a "Wireless" connection

While $ItemIndex > -1

$ConnectionName = ControlListView("Network Connections", "", 1, "GetText", $ItemIndex)

If StringInStr ($ConnectionName, "wireless",2) Then

ExitLoop

ElseIf $ItemIndex = 0 Then

SplashOff()

;Enable keyboard and mouse input

BlockInput (0)

MsgBox (16, "Error", "Unable to locate your Wireless adapter")

Exit

Else

$ItemIndex = $ItemIndex - 1

EndIf

Wend

ControlSetText("LSUSecure WiFi", "", "Static1", ControlGetText ("LSUSecure WiFi", "", "Static1" ) & "...Done")

;Select the Wireless connection

ControlListView("Network Connections", "", 1, "Select", $ItemIndex)

ControlSetText("LSUSecure WiFi", "", "Static1", ControlGetText ("LSUSecure WiFi", "", "Static1" ) & @CRLF & @CRLF & " -Adding the LSUSecure SSID")

;Open Wireless Connection's Properties

ControlSend ("Network Connections", "", "", "!fr")

Can anyone think of a better way to "find" the WiFi connection and get me to the properties window? I'd love to be able to get rid of this whole section of code, pull the GUID for the interface out of the registry and somehow launch right into "Wireless Network Connection Properties" and do my thing but I can't figure out how to make that happen.

Worst case I think I could fix it by waiting a couple of seconds and trying ControlSend ("Network Connections", "", "", "!fr") again but I'd like to have a slicker way of finding their connection.

Any ideas?

Thanks,

Jeff

Share this post


Link to post
Share on other sites



BTW I've also tried using ControlListView "FindItem" to search the "Network Connections" window. It works but I could not figure out how to do anything but an exact match. So, it would find "Wireless Network Connection" but not "Wireless Network Connection 2". Is there any way to put wild cards into the search string or to change the macthing mode?

Thanks,

Jeff

Share this post


Link to post
Share on other sites

Welcome to the forum.

Maybe you can modify this script...

http://www.autoitscript.com/forum/index.ph...st&p=422510

... to locate the name of any NIC that has wireless in its name and then use your code to set up PEAP.

- but -

you might want to search thru the data in the "DriverDesc" value for each key here:

HKEY_LOCAL_MACHINE\

SYSTEM\

CurrentControlSet\

Control\

Class\

{4D36E972-E325-11CE-BFC1-08002bE10318}\

Once you know the reg entry of interest, use the data for the "ComponentId" value for the name of the NIC as it appears within the "Network Connections" window. [users can rename each NIC from that window - so they may not say wireless at all... but they probably did not rename the driver description.]

Once you know the exact name of the NIC of interest ControlListView "FindItem" should work well for you.

...hope this helps...


[size="1"][font="Arial"].[u].[/u][/font][/size]

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Welcome to the forum.

Maybe you can modify this script...

http://www.autoitscript.com/forum/index.ph...st&p=422510

... to locate the name of any NIC that has wireless in its name and then use your code to set up PEAP.

<_<

Like this: ? (Note: only tested on XP, and I only have one Wireless NIC, but should work)

#include <array.au3>
$aWirelessConns = _EnumWireless()

If @extended Then
    ;cycle through the array here and perform actions
    MsgBox(0, "EnumWireless", "@ERROR: " & @error & @CRLF & @CRLF & "# of Wireless Adapters detected: " & @extended)
    _ArrayDisplay($aWirelessConns)
Else
    MsgBox(0, "EnumWireless", "@ERROR: " & @error & @CRLF & @CRLF & "# of Wireless Adapters detected: " & @extended)
EndIf

Func _EnumWireless()
    ;On Success - returns an Array of the Wireless Adapters found. If none found then @Error = 1
    ;Sets @Extended to number of adapters found, If WMI output is empty, then sets @Error = 2
    $sWirelessList = ""
    $wbemFlagReturnImmediately = 0x10
    $wbemFlagForwardOnly = 0x20
    $colItems = ""
    $strComputer = "localhost" 
    $objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")
    $colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_NetworkAdapter", "WQL", _
            $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
    If IsObj($colItems) Then
        For $objItem In $colItems
            If StringRegExp($objItem.Description, "(?i).*Wireless.*Connection") Then $sWirelessList &= $objItem.Description & "|" 
        Next
        $sWirelessList = StringTrimRight($sWirelessList, 1)
        If StringStripWS($sWirelessList, 3) = "" Then
            $Error = 1
        Else
            $aWirelessList = StringSplit($sWirelessList, "|")
            Return SetError(0, UBound($aWirelessList) - 1, $aWirelessList)
        EndIf
    Else
        $Error = 2 ;MsgBox(0, "WMI Output", "No WMI Objects Found for class: " & "Win32_NetworkAdapter")
    EndIf

    Dim $aWirelessList[1]
    $aWirelessList[0] = 0
    Return SetError($Error, 0, $aWirelessList)

EndFunc   ;==>_EnumWireless

Edit: Added some commenting, fixed returns & @Extended, etc

Edited by ResNullius

Share this post


Link to post
Share on other sites

This is good information.

ResNullius, could you please explain this code:

"(?i).*Wireless.*Connection"

When I run your code I get 0 wireless adapters detected. I inserted this line to see what was going on:

msgbox (0, "", $objItem.Description)

In the resulting message boxes I do see my Wireless adapter's description and it has "wireless" in the description however I still get 0 connections found.

I'm thinking I might need to modify that search string a little but I'm not sure how to do it.

Aside from actually "finding" the adapter/connection does anyone have any ideas on pulling up that adapters properties other than selecting it in Network connections and ControlSending an Alt+Enter to the window?

Thanks,

Jeff

Share this post


Link to post
Share on other sites

This is good information.

ResNullius, could you please explain this code:

"(?i).*Wireless.*Connection"

When I run your code I get 0 wireless adapters detected. I inserted this line to see what was going on:

msgbox (0, "", $objItem.Description)

In the resulting message boxes I do see my Wireless adapter's description and it has "wireless" in the description however I still get 0 connections found.

I'm thinking I might need to modify that search string a little but I'm not sure how to do it.

Aside from actually "finding" the adapter/connection does anyone have any ideas on pulling up that adapters properties other than selecting it in Network connections and ControlSending an Alt+Enter to the window?

Thanks,

Jeff

I took out ".*Connection" and it's working now.

Share this post


Link to post
Share on other sites

This is good information.

ResNullius, could you please explain this code:

"(?i).*Wireless.*Connection"

I took out ".*Connection" and it's working now.

You got it!

The "(?i).*Wireless.*Connection" is a regular expression that matches anything with that in the description.

The "(?i)" means case insensitive matching from here on, and the rest of it is

.* = Match any character(s) , any number of times

Wireless = followed by the word Wireless

.* = Match any more character(s) , any number of times

Connection = followed by the word "Connection"

Did it that way as in the other thread we were after Intel connections and all of them (that I've seen) use "wireless" and "connection" in the description.

I have kludged together some code that will also retrieve the "friendly names" as displayed in the "Network Connections" window, and if that will help I can clean it up a bit and post it. Let me know if you want to see it.

Share this post


Link to post
Share on other sites

BTW I've also tried using ControlListView "FindItem" to search the "Network Connections" window. It works but I could not figure out how to do anything but an exact match. So, it would find "Wireless Network Connection" but not "Wireless Network Connection 2". Is there any way to put wild cards into the search string or to change the macthing mode?

Thanks,

Jeff

Finding the Adapter is one thing... but what's about the settings? I tried with modifying the registry, but had no success (maybe this is interesting http://www.derkeiler.com/Newsgroups/micros...5-06/0126.html)

Did you find a way to set the 802.1x stuff in the right way?

Share this post


Link to post
Share on other sites

Finding the Adapter is one thing... but what's about the settings? I tried with modifying the registry, but had no success (maybe this is interesting http://www.derkeiler.com/Newsgroups/micros...5-06/0126.html)

Did you find a way to set the 802.1x stuff in the right way?

Yeah, I started trying to do it through the registry but couldn't get it to work for more than one adapter type at a time because each adapter's driver seems to store things under the Interfaces key differently. That's some good info in that link above though.

I'm using ControlCommand, ControlClick, etc. to simulate that the user is configuring it themselves. After many hours of constant tweaking I think it's working pretty well. I've run it hundreds of times on about 10 test machines running several different management utilities and it's pretty stable at this point.

If all I needed was a configuration utility for my own use I'd be done. The problem is I need to have a re-distributable app that I can give to users, the can run it and connect to our WiFi network. That means it needs to be almost completely idiot proof and accommodate just about every 3rd party utility out there.

Most 3rd party utilities "Yield" to Wireless Zero Config but some, like the Dell/Broadcomm utility, do not and must be stopped before WZCSVC will work properly. You'll see in my code where I look for the Broadcomm utility and disable its service. It's going to just take time for me to encounter all of the major utilities that don't play nice so that I can stop them in the appropriate manner.

XP_LSUSecure_WiFi.au3

Share this post


Link to post
Share on other sites

okay, thank you for the information and script. No i'am sure that settings have to be done in this way... (simulate clicks etc)

My original approach was to import certificates and then use it for (wired) 802.1x authentication. And like you do, deploy a simple tool to all users. This tool should pick up certificates and set interface settings.

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

BTW I've also tried using ControlListView "FindItem" to search the "Network Connections" window. It works but I could not figure out how to do anything but an exact match. So, it would find "Wireless Network Connection" but not "Wireless Network Connection 2". Is there any way to put wild cards into the search string or to change the macthing mode?

Thanks,

Jeff

Hi folks,

Has anyone ever been able to solve the above problem, I cannot find a way to use a broader way of searching using "FindItem" '*Wireless'. Anyone know a better way to find your wireless adapter no matter what it's called and call it's properties.

Thanks in advance.

Edit

I already tried using the attached code to call the properties, but it's a bit beyond me using WMI. If it's possible I'd like to use finditem *Wireless* . Or if anyone can get the attached code to call properties of the wireless nic as a function.

Thanks again

#include <array.au3>

$aWirelessConns = _EnumWireless()

If @extended Then

;cycle through the array here and perform actions

MsgBox(0, "EnumWireless", "@ERROR: " & @error & @CRLF & @CRLF & "# of Wireless Adapters detected: " & @extended)

_ArrayDisplay($aWirelessConns)

Else

MsgBox(0, "EnumWireless", "@ERROR: " & @error & @CRLF & @CRLF & "# of Wireless Adapters detected: " & @extended)

EndIf

Func _EnumWireless()

;On Success - returns an Array of the Wireless Adapters found. If none found then @Error = 1

;Sets @Extended to number of adapters found, If WMI output is empty, then sets @Error = 2

$sWirelessList = ""

$wbemFlagReturnImmediately = 0x10

$wbemFlagForwardOnly = 0x20

$colItems = ""

$strComputer = "localhost"

$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")

$colItems = $objWMIService.ExecQuery ("SELECT * FROM Win32_NetworkAdapter", "WQL", _

$wbemFlagReturnImmediately + $wbemFlagForwardOnly)

If IsObj($colItems) Then

For $objItem In $colItems

If StringRegExp($objItem.Description, "(?i).*Wireless.*Connection") Then $sWirelessList &= $objItem.Description & "|"

Next

$sWirelessList = StringTrimRight($sWirelessList, 1)

If StringStripWS($sWirelessList, 3) = "" Then

$Error = 1

Else

$aWirelessList = StringSplit($sWirelessList, "|")

Return SetError(0, UBound($aWirelessList) - 1, $aWirelessList)

EndIf

Else

$Error = 2 ;MsgBox(0, "WMI Output", "No WMI Objects Found for class: " & "Win32_NetworkAdapter")

EndIf

Dim $aWirelessList[1]

$aWirelessList[0] = 0

Return SetError($Error, 0, $aWirelessList)

EndFunc ;==>_EnumWireless

Edited by Remo1075

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0