WLANManager support for multiple wireless interfaces
This commit is contained in:
parent
e46739a510
commit
3364719ba1
@ -60,6 +60,10 @@ static int WLANManager()
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
wstring interface_name;
|
||||||
|
if (nArgs >= 5 && _wcsicmp(pwcArglist[3], L"interface") == 0)
|
||||||
|
interface_name = pwcArglist[4];
|
||||||
|
|
||||||
// Open WLAN handle.
|
// Open WLAN handle.
|
||||||
DWORD dwNegotiatedVersion;
|
DWORD dwNegotiatedVersion;
|
||||||
wlan_handle wlan;
|
wlan_handle wlan;
|
||||||
@ -83,20 +87,54 @@ static int WLANManager()
|
|||||||
interfaces.reset(pInterfaceList);
|
interfaces.reset(pInterfaceList);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tstring_guid devclass_net(GUID_DEVCLASS_NET);
|
||||||
|
bool profile_found = false;
|
||||||
for (DWORD i = 0; i < interfaces->dwNumberOfItems; i++) {
|
for (DWORD i = 0; i < interfaces->dwNumberOfItems; i++) {
|
||||||
if (interfaces->InterfaceInfo[i].isState == wlan_interface_state_not_ready) {
|
if (interfaces->InterfaceInfo[i].isState == wlan_interface_state_not_ready) {
|
||||||
// This interface is not ready.
|
// This interface is not ready.
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!interface_name.empty()) {
|
||||||
|
// Read the interface name from registry.
|
||||||
|
reg_key key;
|
||||||
|
if (key.open(HKEY_LOCAL_MACHINE, tstring_printf(_T("SYSTEM\\CurrentControlSet\\Control\\Network\\%s\\%s\\Connection"), devclass_net.c_str(), tstring_guid(interfaces->InterfaceInfo[i].InterfaceGuid).c_str()).c_str(), 0, KEY_READ)) {
|
||||||
|
wstring name;
|
||||||
|
if (RegQueryStringValue(key, _T("Name"), name) == ERROR_SUCCESS && _wcsicmp(interface_name.c_str(), name.c_str()) != 0) {
|
||||||
|
// Not the interface we are interested in.
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
unique_ptr<WLAN_PROFILE_INFO_LIST, WlanFreeMemory_delete<WLAN_PROFILE_INFO_LIST> > profiles;
|
||||||
|
{
|
||||||
|
// Get a list of profiles.
|
||||||
|
WLAN_PROFILE_INFO_LIST *pProfileList;
|
||||||
|
DWORD dwResult = WlanGetProfileList(wlan, &(interfaces->InterfaceInfo[i].InterfaceGuid), NULL, &pProfileList);
|
||||||
|
if (dwResult != ERROR_SUCCESS) {
|
||||||
|
DisplayError(_T("%s function failed (error %u)."), _T("WlanGetProfileList"), dwResult);
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
|
profiles.reset(pProfileList);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (DWORD j = 0; j < profiles->dwNumberOfItems; j++)
|
||||||
|
if (_wcsicmp(profiles->ProfileInfo[j].strProfileName, pwcArglist[2]) == 0) {
|
||||||
|
profile_found = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!profile_found)
|
||||||
|
continue;
|
||||||
|
|
||||||
// Launch WLAN profile config dialog.
|
// Launch WLAN profile config dialog.
|
||||||
WLAN_REASON_CODE wlrc;
|
WLAN_REASON_CODE wlrc = L2_REASON_CODE_SUCCESS;
|
||||||
DWORD dwResult = WlanUIEditProfile(WLAN_UI_API_VERSION, pwcArglist[2], &(interfaces->InterfaceInfo[i].InterfaceGuid), NULL, WLSecurityPage, NULL, &wlrc);
|
DWORD dwResult = WlanUIEditProfile(WLAN_UI_API_VERSION, pwcArglist[2], &(interfaces->InterfaceInfo[i].InterfaceGuid), NULL, WLSecurityPage, NULL, &wlrc);
|
||||||
if (dwResult != ERROR_SUCCESS) {
|
if (dwResult != ERROR_SUCCESS) {
|
||||||
DisplayError(_T("%s function failed (error %u)."), _T("WlanUIEditProfile"), dwResult);
|
DisplayError(_T("%s function failed (error %u)."), _T("WlanUIEditProfile"), dwResult);
|
||||||
return 5;
|
return 5;
|
||||||
}
|
} else if (wlrc != WLAN_REASON_CODE_SUCCESS) {
|
||||||
if (wlrc != WLAN_REASON_CODE_SUCCESS) {
|
|
||||||
tstring reason;
|
tstring reason;
|
||||||
if (WlanReasonCodeToString(wlrc, reason, NULL) == ERROR_SUCCESS)
|
if (WlanReasonCodeToString(wlrc, reason, NULL) == ERROR_SUCCESS)
|
||||||
DisplayError(_T("%s function failed: %s"), _T("WlanUIEditProfile"), reason.c_str());
|
DisplayError(_T("%s function failed: %s"), _T("WlanUIEditProfile"), reason.c_str());
|
||||||
@ -107,6 +145,9 @@ static int WLANManager()
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!profile_found)
|
||||||
|
DisplayError(_T("%ls profile not found."), pwcArglist[2]);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ Invokes standard Windows Wireless Network Properties dialog
|
|||||||
|
|
||||||
##Usage
|
##Usage
|
||||||
```
|
```
|
||||||
WLANManager profile <name>
|
WLANManager profile <name> [interface <name>]
|
||||||
```
|
```
|
||||||
|
|
||||||
- `name` - The name of the network profile (not neccessarely the same as SSID)
|
- `name` - The name of the network profile (not neccessarely the same as SSID)
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
|
|
||||||
#include <Windows.h>
|
#include <Windows.h>
|
||||||
#include <CommCtrl.h>
|
#include <CommCtrl.h>
|
||||||
|
#include <devguid.h>
|
||||||
#include <tchar.h>
|
#include <tchar.h>
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user