Enterprise WLAN profile deployment with .bat script

I will demonstrate how to mass deploy WLAN profiles with simple .bat scripts and wlan.exe utility from Microsoft. Active Directory GPO prior to 2003 native mode doesn’t give you the option to mass deploy WLAN profiles. Also if you don’t run AD infrastructure at all and want a simple script you will find this useful.
Script takes into account that some clients don’t have Wireless card and will skip them.

Deployment environment:
AD Infrastructure – 2000 Native mode
Clients: Windows XP SP3 (wlan.exe requires SP3, later versions such as Vista and 7 come with utility)

Step 1
You first need to configure a profile on one of the clients and than export it using wlan.exe utility. To export profile you need to run wlan.exe utility in command prompt.
Find GUID of your wireless adapter; issue this command: wlan.exe ei
Interface 0:
GUID: 00045340-cf09-4c5b-8f27-1bc000000a9c
Broadcom 4321AG 802.11a/b/g/draft-n Wi-Fi Adapter
State: “connected”

Find if the profile exists on this interface; issue this command: wlan gpl 00045340-cf09-4c5b-8f27-1bc000000a9c Please make sure “template” profile you configured is there.
Now we export it as a .xml file: wlan.exe gp 00045340-cf09-4c5b-8f27-1bc000000a9c “dd-wrt” C:\templt.xml
Finally, open exported file and remove first and last line:
The return profile xml is:
Command “gp” completed successfully.

Step 2
Now we will import this profile. Using 2 .bat scripts. First one checks if the client has wireless card and if it is true we copy required files to %temp% folder and executes 2nd script, which imports WLAN profile you created in step 1.
Note: wlan.exe utility doesn’t work properly if it runs from the network share, thus we have to copy to %temp% and call it from there.

@echo off
rem Date: March 17, 2011
rem Author: Naz Snidanko
rem Description: checks for wifi adapt, copies files to temp dir and runs deployment script and cleans
ipconfig | findstr "Wireless"
if %errorlevel% EQU 0 goto wifi
if %errorlevel% EQU 1 goto nowifi
mkdir %temp%\WLAN
copy "\\share.com\NETLOGON\WLAN\*.*" %temp%\WLAN
call %temp%\WLAN\WLAN_exec.bat
rmdir /S /Q %temp%\WLAN

And thats the script that will execute (it is called as WLAN_exec.bat from previous script)

@echo off
rem Date: March 16, 2011
rem Author: Naz Snidanko
rem Description: Manual deployment of wireless profiles on Windows XP SP3
set wifiprofile="profile.xml"
For /F "skip=2 tokens=1,2" %%A IN ('%temp%\WLAN\wlan.exe ei') Do If "%%A"=="GUID:" set Interface=%%B
%temp%\WLAN\wlan.exe sp %Interface% %wifiprofile%

Download wlan.exe utility

Hope it helps, cheers!

This entry was posted in .bat scripts, Random stuff and tagged , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *