Scott Hanselman

How to connect to a Wireless WIFI Network from the Command line in Windows 7

July 28, 2011 Comment on this post [13] Posted in Tools
Sponsored By

For the humorless amongst you who didn't find these Updated for 2011 - McDonald's WiFi Guide with updates for Mac OS X Lion and Windows 7 to be HIGH-LARIOUS, the question was asked, "well, sir, how do you connect to a Wireless WIFI Network from the Command line in Windows 7?"

The answer, is, ahem, thusly:

C:\>netsh wlan connect name=HANSELMAN-N
Connection request was completed successfully.

Cool.

More Details

What happened there? Well, the command line is netsh wlan and the full one is

netsh wlan connect ssid=YOURSSID name=PROFILENAME

What's a profile? It's the only thing required. You can see them with:

C:\>netsh wlan show profile

Profiles on interface Wireless Network Connection:
.
..snip..
User profiles
-------------
    All User Profile     : Clear Spot b0e
    All User Profile     : HANSELMAN-N
    All User Profile     : Quiznos

These are the same ones that you see in the wireless networks dialog...

Manage Wireless Networks

You can set these up and refer to them by name from the command line, or a batch file, etc. Nice to do for the places you are regularly.

If you have multiple wireless cards (What's wrong with you!?) then you have to be more specific:

netsh wlan connect ssid=YOURSSID name=PROFILENAME interface="WIRELESS NETWORK CONNECTION"

And of course, you can

netsh wlan disconnect

And include the interface optionally, for multiple interfaces. Additionally, interesting things can be seen with

netsh wlan dump

This is nice because you can

netsh wlan dump > myconfig.txt

on one machine and then later on another machine

netsh exec myconfig.txt

All this command line love will work in most versions of Windows, actually, not just 7 AFAIK. There's lots of more detail and docs on managing Wireless Profiles on the Web.

Enjoy!

About Scott

Scott Hanselman is a former professor, former Chief Architect in finance, now speaker, consultant, father, diabetic, and Microsoft employee. He is a failed stand-up comic, a cornrower, and a book author.

facebook twitter subscribe
About   Newsletter
Hosting By
Hosted in an Azure App Service
July 28, 2011 1:08
Maybe this is a dumb question, but what if you have a password on your access point? Will it prompt you?
July 28, 2011 1:08
Funny. My first reaction on reading all that command-line for OS X was to check netsh wlan.

You can also scan available wifi from netsh:

> netsh wlan show newtworks

-or-

> netsh wlan show networks mode=bssid

The latter option gives more detail including signal but (doh!) in some arbitrary percentage not in dBm.

On a related note, I was shocked to hear Leo and friends on MacBreak Weekly actually laugh about this McDonalds card about how much easier it is to connect to WiFi with a Mac.
July 28, 2011 1:31
OMG - Leo and Friends. Sigh.
July 28, 2011 1:32
hmm, interesting...
July 28, 2011 1:41
I am no command line expert but I thought this was interesting so gave it a try (for some reason i get a kick out of command line programs prompting me for password and stuff - iamelephant's question made me want to try ;-)...

Here is what i found (I may be totally wrong - i know a lot of much more knowledgeable people read and post here than me ;-)

this is for connecting to wireless connections you already have set up.. exactly as Scott is saying this is for profiles that already exist.

I deleted the settings for my wifi and then i played around with the help on netsh and long story short it seems like you need something like:

netsh wlan add profile filename="<xml file of config>" interface="wilress Network Interface" User="username"

dunno the format of the xml file..

more info:

http://technet.microsoft.com/en-us/library/cc755301(WS.10).aspx#bkmk_wlanAddProfile

So not so easy or am i totally wrong?
July 28, 2011 1:52
this is the (slightly edited) contents of one of those XML files:


<?xml version="1.0"?>
<WLANProfile xmlns="http://www.microsoft.com/networking/WLAN/profile/v1">
<name>Gordo</name>
<SSIDConfig>
<SSID>
<hex>4723456F</hex>
<name>Gordon</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>true</protected>
<keyMaterial>03t23464265242424523423450000000010660000000100002000000
0CC5FFB0D403BFCF05E3DF424C202898C73E7F3B51E07FCADE900C2A4586972EC000000000E80000000020
00020000000B1D04C43AF0C4AE68BC21A928E4121211BF937FE1F87DD6810C4620605F2860C10000000CE6
18ED134DF169FB47861C14397BB9D40000000A67F0CE51061F5B4DD4D3A88518645A60BB61F8F536524BDD
EE03FC6BADC4DB3EB075E426FE695E7A9CB26F7607D09EC0856D4A0F512209E1D660FCB4BEFF340</keyMaterial>
</sharedKey>
</security>
</MSM>
</WLANProfile>


dunno if you can generate that is some way?
July 28, 2011 2:06
okay so i used this template for a new file:

http://msdn.microsoft.com/en-us/library/aa370029(v=VS.85).aspx

I had tried cutting bits out of the old one but that was not happening

it was very easy, then i disconnected the other wifi network i was connected to and up popped the same password box you get when you join any wifi network and BAM I am connected and posting on the hanselmasters site ;-)
July 28, 2011 2:10
Here is the security part of that template:

<security>
<authEncryption>
<authentication>WPAPSK</authentication>
<encryption>TKIP</encryption>
<useOneX>false</useOneX>
</authEncryption>
</security>

i get the useOneX being false tells it to set up the shared authentication stuffs?

anyways ill stop bloating you comments.. sorry
July 28, 2011 15:36
Nice tips
July 28, 2011 18:04
I thought it interesting that today (7/27/2011) was the 30th Anniversary Anniversary of DOS and Scott handed out a Commandline "howto" ! In my opinion, more of these are needed to remind us of our roots (at least those of us who have been around long enough to remember the early days of DOS) ! ;-)
July 28, 2011 19:54
Sadly this does not work for XP. wlan is not a known netsh command. Works very nicely in >= Vista though.
July 30, 2011 4:39
Finally, Win7 command line becoming more powerful than the Mac Terminal. Well, I guess powershell has been on the on rise for some time now and Apple and seems to have been dumbing down power features in their OSs for some time now. This seems to be culminating in Lion...
September 05, 2011 3:45
Hello. Plz help me set up an executable file that i can schedule to connect to my mobile broadband. Im running win7
Sam

Comments are closed.

Disclaimer: The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.