Page 1 of 1

Wifi Profiles

Posted: 26 Nov 2012 05:11
by Dipesh
Hello to all,

i have few different-different ssid for wifi connectivity so i want a wifi profile create script that add profile in wifi network so i have this...

netsh wlan add profile filename=my.xml

Xml file is here:

<?xml version="1.0"?>
<WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1">
<name>my</name>
<SSIDConfig>
<SSID>
<name>ssid</name>
</SSID>
<nonBroadcast>true</nonBroadcast>
</SSIDConfig>
<connectionType>ESS</connectionType>
<connectionMode>auto</connectionMode>
<MSM>
<security>
<authEncryption>
<authentication>WPA2PSK</authentication>
<encryption>AES</encryption>
<useOneX>false</useOneX>
</authEncryption>
<sharedKey>
<keyType>passPhrase</keyType>
<protected>false</protected>
<keyMaterial>wifi</keyMaterial>
</sharedKey>
</security>
</MSM>
</WLANProfile>

my code:


CLS
@ECHO OFF

:MENU
CLS
ECHO -------------------------------------
ECHO ========= WiFi Profile Setup ========
ECHO -------------------------------------
ECHO 1. Setup All Unit WiFi Profile.
SET INPUT=
SET /P INPUT=Please select a number:

IF /I '%INPUT%'=='1' GOTO :Selection1
IF /I '%INPUT%'=='2' GOTO :Selection2
:Selection1

echo <?xml version="1.0"?> >> "wifi.xml"
echo <WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1">>> "wifi.xml"
echo <name>my</name> >> "wifi.xml"
echo <SSIDConfig> >> "wifi.xml"
echo <SSID> >> "wifi.xml"
echo <name>ssid</name> >> "wifi.xml"
echo </SSID> >> "wifi.xml"
echo <nonBroadcast>true</nonBroadcast> >> "wifi.xml"
echo </SSIDConfig> >> "wifi.xml"
echo <connectionType>ESS</connectionType> >> "wifi.xml"
echo <connectionMode>auto</connectionMode> >> "wifi.xml"
echo <MSM> >> "wifi.xml"
echo <security> >> "wifi.xml"
echo <authEncryption> >> "wifi.xml"
echo <authentication>WPA2PSK</authentication> >> "wifi.xml"
echo <encryption>AES</encryption> >> "wifi.xml"
echo <useOneX>false</useOneX> >> "wifi.xml"
echo </authEncryption> >> "wifi.xml"
echo <sharedKey> >> "wifi.xml"
echo <keyType>passPhrase</keyType> >> "wifi.xml"
echo <protected>false</protected> >> "wifi.xml"
echo <keyMaterial>wifi</keyMaterial> >> "wifi.xml"
echo </sharedKey> >> "wifi.xml"
echo </security> >> "wifi.xml"
echo </MSM> >> "wifi.xml"
echo </WLANProfile> >> "wifi.xml"

netsh wlan add profile filename=wifi.xml


BUT IS NOT WORKING PLEASE GUIDE WHAT TO DO ??

Re: Wifi Profiles

Posted: 26 Nov 2012 05:22
by abc0502
Edited
Forgot echo before each line

You have a huge un-escaped character which is > and <
add before each one of them this sign ^ to escape them when echo the data.

This is a better way to echo content to files:

Code: Select all

(
echo ^<?xml version="1.0"?^>
echo ^<WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1"^>
echo ^<name^>my^</name^>
echo ^<SSIDConfig^>
echo ^<SSID^>
echo ^<name^>ssid^</name^>
echo ^</SSID^>
echo ^<nonBroadcast^>true^</nonBroadcast^>
echo ^</SSIDConfig^>
echo ^<connectionType^>ESS^</connectionType^>
echo ^<connectionMode^>auto^</connectionMode^>
echo ^<MSM^>
echo ^<security^>
echo ^<authEncryption^>
echo ^<authentication^>WPA2PSK^</authentication^>
echo ^<encryption^>AES^</encryption^>
echo ^<useOneX^>false^</useOneX^>
echo ^</authEncryption^>
echo ^<sharedKey^>
echo ^<keyType^>passPhrase^</keyType^>
echo ^<protected^>false^</protected^>
echo ^<keyMaterial^>wifi^</keyMaterial^>
echo ^</sharedKey^>
echo ^</security^>
echo ^</MSM^>
echo ^</WLANProfile^>
)>"wifi.xml"

Re: Wifi Profiles

Posted: 26 Nov 2012 22:30
by Dipesh
It's working fine.
Thanking you very much bro.

but one help if possible I want to set variable at "name" , "ssid" & "Sharedkey"
so that if options 1 select then the three value come with their variable
& if option 2 Select then value come with this parameter & if the select ALL then
all the profile wit add(all variable parameter).

Thanks again.

Re: Wifi Profiles

Posted: 27 Nov 2012 00:04
by abc0502
Do you mean that when selecting first option, it create the xml file with it's default values,
And when selecting second option it ask for name, ssid & sharedkey then create the xml file with this values ?

or do you mean that for each selection has it's own name, ssid & sharedkey that needs to be inserted in the form of the xml file depending on the option ?

and after executing the command "netsh" , is it important to keep the xml file or it will be ok if the batch delete it after it's done?

If you can explain as possible in details that will make it easier and faster for me to help you.

Re: Wifi Profiles

Posted: 27 Nov 2012 03:05
by Dipesh
Thanks for the replay.

that for each selection has it's own name, ssid & sharedkey that needs to be inserted in the form of the xml file depending on the option ?(user not input anything just selecting options name , sharedkey & ssid in variable .)

nothing to input when batch run just select option & it will create profile like option wise.
& it is okey if file delete after netsh command.

BUT ONE THING IS, IF USER SELECT INSTALL ALL PROFILE THEN ??? like there 5 options with different - different options but one options for all 5 profile options. if options 6 select the all 5 profile should install.

Re: Wifi Profiles

Posted: 27 Nov 2012 04:18
by abc0502
HI, I didn't exactly understand the last part
BUT ONE THING IS, IF USER SELECT INSTALL ALL PROFILE THEN ??? like there 5 options with different - different options but one options for all 5 profile options. if options 6 select the all 5 profile should install.


But Here is the batch depending on my understanding to your request in general:
You will have to change the "Name", "SSID", "SharedKey" under each option tags ":Option1", ":Option2" & ":Option3", and optionally the "xml_name" and ofcourse the menu names to this profiles that will be displayed in on the CMD window.
Also, The ":XML" tag dosen't need any changes.

Code: Select all

@Echo OFF
Title WiFi Profile Manager
Color 0E
Mode 50,15

:Menu
Cls & Echo.
Echo              ========================
Echo             ^<^<^<     Setup Menu     ^>^>^>
Echo              ========================
Echo.
Echo       ^<1^> Option One
Echo       ^<2^> Option Two
Echo       ^<3^> Option Three
Echo       ^<4^> Option ALL
Echo       ^<5^> Exit

Echo.

Set "choice="
Set /p "choice=    Option: "
IF NOT DEFINED choice GOTO :Menu

IF "%choice%" == "1" Call :Option1
IF "%choice%" == "2" Call :Option2
IF "%choice%" == "3" Call :Option3
IF "%choice%" == "4" Call :All
IF "%choice%" == "5" Goto :EOF

Exit /B

:Option1
set "Name=wifi_1"
set "SSID=SSID_1"
set "SharedKey=Password_1"
set "xml_name=option1.xml"
   Call :XML "%Name%" "%SSID%" "%SharedKey%" "%xml_name%"
   netsh wlan add profile filename=%xml_name%
   Del /F /Q "%xml_name%" >nul
   Goto :eof

:Option2
set "Name=wifi_2"
set "SSID=SSID_2"
set "SharedKey=Password_2"
set "xml_name=option2.xml"
   Call :XML "%Name%" "%SSID%" "%SharedKey%" "%xml_name%"
   netsh wlan add profile filename=%xml_name%
   Del /F /Q "%xml_name%" >nul
   Goto :eof

:Option3
set "Name=wifi_3"
set "SSID=SSID_3"
set "SharedKey=Password_3"
set "xml_name=option3.xml"
   Call :XML "%Name%" "%SSID%" "%SharedKey%" "%xml_name%"
   netsh wlan add profile filename=%xml_name%
   Del /F /Q "%xml_name%" >nul
   Goto :eof

:All
Call :Option1
Call :Option2
Call :Option3
Goto :EOF

:XML [XML setting File form]
:: Take 4 inputs: Name, SSID, SharedKey & output xml file name.
set "Name=%~1"
set "SSID=%~2"
set "SharedKey=%~3"
set "output=%~4"
(
echo ^<?xml version="1.0"?^>
echo ^<WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1"^>
echo ^<name^>%Name%^</name^>
echo ^<SSIDConfig^>
echo ^<SSID^>
echo ^<name^>%SSID%^</name^>
echo ^</SSID^>
echo ^<nonBroadcast^>true^</nonBroadcast^>
echo ^</SSIDConfig^>
echo ^<connectionType^>ESS^</connectionType^>
echo ^<connectionMode^>auto^</connectionMode^>
echo ^<MSM^>
echo ^<security^>
echo ^<authEncryption^>
echo ^<authentication^>WPA2PSK^</authentication^>
echo ^<encryption^>AES^</encryption^>
echo ^<useOneX^>false^</useOneX^>
echo ^</authEncryption^>
echo ^<sharedKey^>
echo ^<keyType^>%SharedKey%^</keyType^>
echo ^<protected^>false^</protected^>
echo ^<keyMaterial^>wifi^</keyMaterial^>
echo ^</sharedKey^>
echo ^</security^>
echo ^</MSM^>
echo ^</WLANProfile^>
)>"%output%"
Goto :EOF


>When you run it , you choose one of the 1st 3 options and it will create it's xml file based on each option settings and install that xml and then delete.
>The 4th option "All" will install all previous options one by one.

To add more options Here is what you will have to do:
1> add another line in the menu part to display that option on with other choices.
2> add IF statement after the last option and before the Exit.
3> add a new tag like ":OptionX" and copy one of the other options commands and paste it under that new tag then modify only the Name, SSID, SharedKey & xml_name variable.
4> finally, add a new line under the ":All" like the previous commands and change Only the tag name with your new one.

That's All :)

Re: Wifi Profiles

Posted: 27 Nov 2012 04:22
by abc0502
BTW, I assumed that :
> Name is what between this tags
<name>my</name>
which in this case is "my"
> SSID is what between this tag
<name>ssid</name>
which in this case is "ssid"
> SharedKey is what between this tag
<keyType>passPhrase</keyType>
which also in this key is "passPhrase"

Re: Wifi Profiles

Posted: 28 Nov 2012 02:00
by Dipesh
Thanks bro.

Yes exactly that what i want.