Reputation: 499
I'm developing a way to connect to a Wifi using VS2010 and currently stuck on how to make it connect with a network security key. I am able to enumerate all the Wifi hotspot in my area and get their SSID, MAC addresses, etc using Windows Native Wifi Functions (WlanOpenHandle, WlanEnumInterfaces, WlanQueryInterface, WlanGetNetworkBssList). I've already read about WlanConnect()
on MSDN but I'm still clueless. Can you give me some hints that would make the code connect to a Wifi that asks for a network security key?
Upvotes: 3
Views: 3636
Reputation: 31
You will need an example profile to start with, as arx had suggested. When exporting a profile, add the key=clear arg. This will export the profile with the key in it. You can than see the setup that you would need to adjust.
Example : netsh wlan export profile name=”<profileName>” folder=”<SaveLocation>” key=clear
The resulting xml will contain a section with:
<MSM>
<security>
<authEncryption>
<authentication>WPA2PSK</authentication>
<encryption>AES</encryption>
<useOneX>false</useOneX>
</authEncryption>
<sharedKey>
<keyType>passPhrase</keyType>
<protected>false</protected>
<keyMaterial>YourPaswordTextHERE</keyMaterial>
</sharedKey>
</security>
</MSM>
So once you have your profile string, update the keyMaterial element with your programmatically obtained password. Once this is done you should be able to call wlanConnect.
Upvotes: 1
Reputation: 16896
Assuming you have at least one saved Wifi connection run the command
netsh wlan export profile
This will export all your Wifi profiles as XML files in the current directory.
When you call WlanConnect
you can supply a literal XML profile string in the WLAN_CONNECTION_PARAMETERS
structure if wLanConnectionMode
is set to wlan_connection_mode_temporary_profile
.
If you can use the XML from one of your exported profiles to connect successfully to a secured network, then presumably you should be able to alter the XML and use the same technique to connect to new networks.
I've never tried this, and I've no idea what encoding is used for the key stored in the XML, but it seems like a possible way of solving your problem.
Upvotes: 1