Capturing & Deploying WLAN Profiles

February 27th, 2009 by Rob Milner 7 Comments

For a long time I have been trying to find a solution for rolling out a standard wireless profile so that anyone with a Laptop can visit any remote site with a WIFI connection and just connect without searching for a new network and without entering a new password everytime.

I stumbled upon the solution the other day whilst trying to solve another problem. If you take a look at this webpage that is on the Symantec Juice website (click here). If you use the file attached at the bottom of the post called WLAN.exe, it will allow you to export an existing WLAN profile saved on your laptop into an XML file. What you can do then do is create a script to import the XML file using the WLAN.exe utility to create the WLAN profile. What I have done is use Altiris to run this script on all client computers, as this process made it very simple to deploy. The script can be found at the end of this blog.

Firstly, you will need to have the WLAN profile already created on your computer. In my case I set-up a test WLAN environment with an SSID of “Test-Wireless” along with a WPA key of “@test-w1rele55!”. Once this was saved, I could use the utility to export the Test-Wireless profile to the XML file (you only need to do this once as long as the settings do not change!). But first, you need to do the following:

You need to find the GUID of your WIFI card, which you can find out by using the WLAN.exe tool and issuing the following command:

WLAN.exe ei
There are 1 interfaces in the system.
Interface 0:
GUID: 4ccd4bf2-4876-4993-a3de-3ed1cdf54eeb
Intel(R) PRO/Wireless 3945ABG Network Connection - Packet Scheduler Mini port
State: “connected”
Command “ei” completed successfully.

You then need to export the WLAN profile for your chosen WLAN network (in this case “Test-Wireless). In the below example you need to pass WLAN.exe your GUID of your WIFI card:

WLAN.exe gp 4CCD4BF2-4876-4993-A3DE-3ED1CDF54EEB Test-Wireless

This then produces the following ouput in the command prompt window:

< ?xml version="1.0"?>
<wlanprofile xmlns=”http://www.microsoft.com/networking/WLAN/profile/v1″>
<name>Test-Wireless</name>
<ssidconfig>
<ssid>
<hex>4A4E422D576972656C657373</hex>
<name>Test-Wireless</name>
</ssid>
</ssidconfig>
<connectiontype>ESS</connectiontype>
<msm>
<security>
<authencryption>
<authentication>WPA2PSK</authentication>
<encryption>TKIP</encryption>
<useonex>false</useonex>
</authencryption>
<sharedkey>
<keytype>networkKey</keytype>
<protected>false</protected>
<keymaterial>12754EB0C3B25D3F9268E1C49C1E09E5FAD4F9930A67CEB8E3BC944A68047D67</keymaterial>
</sharedkey>
</security>
</msm>
</wlanprofile>

If you copy and paste the text into Notepad, you will be able to save it as an XML file (call it testwireless.xml).

Now that you have captured your WLAN profile, you are ready to think about deploying the profile. To deploy, test it on your computer. Delete the Test-Wireless network in your WLAN network list, and then issue the following command:

WLAN.exe sp 4CCD4BF2-4876-4993-A3DE-3ED1CDF54EEB testwireless.xml

If you check your list of Wireless Networks, you should find that Test-Wireless should be there along with the WPA key already entered!

That is the manual way of doing it, if you need to automate this amongst a different number of computers you face a problem in that for each computer that requires the WLAN profile, the WIFI GUID will be different on each machine! This did cause me some problems, but after messing with PowerShell for a few hours I managed to create a very simple script that will find the GUID of the machine that you want to deploy the profile to and then pass the GUID to the command line. Here is the PowerShell script to automate this:

$path = "HKLM:\Software\Microsoft\WZCSVC\Parameters\Interfaces\"
$guid = Get-ChildItem -name $path
$guid = $guid.TrimStart(”{”)
$guid = $guid.TrimEnd(”}”)
.\WLAN.exe sp $guid testwireless.xml

And there you have an automated way of deploying a WLAN profile. This will prove to be a great time saver for our IT department & I hope someone will find this useful!

7 Responses to “Capturing & Deploying WLAN Profiles”

pascal

March 16th, 2009 - 6:48 pm

did you have a version without powershell ? maybe vb script? powershell isn’t installed on the most clients.

thx

Rob Milner

March 17th, 2009 - 9:22 am

Hi, it should be fairly easy to implement the same thing in vbscript (although not as easy as powershell). You should maybe think about rolling out powershell is as it much more powerful than vbscript and it will eventually replace vbscript anyway!

I will try and work on a vbscript version for you if you like?

pascal

March 17th, 2009 - 12:43 pm

hey, that would be great. i am a really bad in scripting.

thx a lot

Rob Milner

March 25th, 2009 - 9:35 pm

Sorry for late reply – I have just finished the vbscript and the contents of the script is below:

(Powershell is much easier in this case – its only 5 lines of code compared to 24 lines of code for VBScript!). Hope you get it working anyway…

option explicit
Dim wshShell, strComputer, strKeyPath, oReg, arrSubKeys, subkey, command

Set wshShell = WScript.CreateObject (”WSCript.shell”)

Const HKEY_LOCAL_MACHINE = &H80000002

strComputer = “.”

Set oReg=GetObject(”winmgmts:{impersonationLevel=impersonate}!\\” & _
strComputer & “\root\default:StdRegProv”)

strKeyPath = “Software\Microsoft\WZCSVC\Parameters\Interfaces\”
oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys

For Each subkey In arrSubKeys
subkey = Replace(subkey, “{”, “”)
subkey = Replace(subkey, “}”, “”)
‘Used for testing: Wscript.Echo “WLAN.exe sp ” & subkey & ” testwireless.xml”
command = “WLAN.exe sp ” & subkey & ” testwireless.xml”

wshShell.run command, 6, True
set wshshell = nothing
Next

pascal

March 26th, 2009 - 9:55 am

perfect. great work.
thx a lot

Geoff

February 15th, 2010 - 12:26 pm

Slight error with the vbscript code there, “set wshshell=nothing” should be the last line, otherwise the script will fail after the first interface (not many systems have more than 1 wifi interface so should be that much of a problem though!)

Rob

February 15th, 2010 - 1:46 pm

Good point Geoff! VB is no longer my scripting choice – so much easier using PS these days.

Leave a Reply