So, I am currently trying to create a batch file to connect to a wireless network. So far I have the following...
@echo off
netsh wlan connect ssid="My SSID" name="My Name"
pause
It works fine, but the issue is that it can only connect to networks that are already in my profiles. Is there any way that I can connect to a wireless network, using a password as an argument, that is not already in my profiles?
You need a xml file that has the SSID and password.
<?xml version="1.0"?>
<WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1">
<name>{example}</name>
<SSIDConfig>
<SSID>
<hex>{6578616d706c65}</hex>
<name>{example}</name>
</SSID>
</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>{password}</keyMaterial>
</sharedKey>
</security>
</MSM>
<MacRandomization
xmlns="http://www.microsoft.com/networking/WLAN/profile/v3">
<enableRandomization>false</enableRandomization>
</MacRandomization>
</WLANProfile>
Fill in the {6578616d706c65}
, {example}
, {example}
and {password}
with your own information.
{6578616d706c65}
is the Hex of example
, click here to convert ASCII to HEX.
Make sure you use the correct format, windows WILL NOT accept even there's one more space at the end.
click here to download example.xml
and other files.
If you want to use pure cmd to connect (without changing the {password}
manually), keep reading
To do this, you will need 36 xml files with a-z and 0-9 (it's not possible to have both caps and lowercase.)
click here to download the 36 files and example.xml.
First you need to separate example.xml into 3 parts, the first part is from <?xml version="1.0"?>
to <keyMaterial>
.
Name that to T.xml
.
The second part is the password.
The third part is from </keyMaterial>
to the end (</WLANProfile>
) make sure you don't forget the line break after </WLANProfile>
.
Name that to B.xml
.
Then you will use the copy command to combine the files.
The code should look like this
copy /y C:\T.xml + C:\keyMaterial\p.xml + C:\keyMaterial\a.xml + C:\keyMaterial\s.xml + C:\keyMaterial\s.xml + C:\keyMaterial\w.xml + C:\keyMaterial\o.xml + C:\keyMaterial\r.xml + C:\keyMaterial\d.xml + C:\B.xml C:\example.xml /B
netsh wlan add profile filename="C:\example.xml" user=all
netsh wlan connect example
Finally, you can check if you're connected by running ping google.com
.
Also, if you know more about connecting to wifi and wifi password please comment below or email me [email protected]
, I will be glad to answer other related questions.