Windows 8、Windows Server 2012 及更高版本包括新的连接管理器功能,允许用户轻松连接到 Internet 和其他网络(例如工作和家庭网络)。 此新的连接管理器功能取代了较旧的 连接到网络 和 管理无线网络 用户界面,这些用户界面包含在较旧版本的 Windows 中,用于管理本机 Wifi 连接。
在 Windows 7、Windows Server 2008 和 Windows Vista 上,有许多用户界面(UI)用于连接到或配置无线网络。 可以使用 Native Wifi 和 Windows Shell 函数在应用程序中启动这些 UI。 这些 UI 在 Windows 8、Windows Server 2012 及更高版本上不可用。
Windows XP SP3 和 Windows XP 无线 LAN API 和 SP2: 无法启动用于以编程方式连接到或配置应用程序中的无线网络的任何 UI。
连接到网络
在 Windows 8、Windows Server 2012、Windows 7、Windows Server 2008 和 Windows Vista 上,连接到网络 向导可用于建立与无线网络的连接。 可以使用 ShellExecute 函数启动 连接到网络 向导。
以下代码显示了启动 连接到网络 向导的 ShellExecute 调用。
#ifndef UNICODE
#define UNICODE
#endif
#include <windows.h>
#include <shellapi.h>
// Need to link with shell32.lib
#pragma comment(lib, "shell32.lib")
void wmain()
{
ShellExecute(
NULL,
L"open",
L"shell:::{21EC2020-3AEA-1069-A2DD-08002B30309D}\\::{38a98528-6cbf-4ca9-8dc0-b1e1d10f7b1b}",
NULL,
NULL,
SW_SHOWNORMAL);
}
管理无线网络
在 Windows 7、Windows Server 2008 和 Windows Vista 上,管理无线网络 控制面板项用于管理无线网络配置文件。 ShellExecute 函数还可用于启动 管理无线网络 项。 在 Windows 7 和 Windows Vista 上调用 ShellExecute 时要使用的路径如下:
shell:::{26EE0668-A00A-44D7-9371-BEB064C98683}\3\::{1fa9085f-25a2-489b-85d4-86326eedcd87}
。
以下示例代码演示如何使用 ShellExecute 从应用程序启动 托管无线网络 向导。
#ifndef UNICODE
#define UNICODE
#endif
#include <windows.h>
#include <shellapi.h>
#include <stdio.h>
// Need to link with shell32.lib
#pragma comment(lib, "shell32.lib")
int wmain()
{
//-----------------------------------------
// Declare and initialize variables
HINSTANCE nResult;
PCWSTR lpOperation = L"open";
PCWSTR lpFile=
L"shell:::{26EE0668-A00A-44D7-9371-BEB064C98683}\\3\\::{1fa9085f-25a2-489b-85d4-86326eedcd87}";
nResult = ShellExecute(
NULL, // Hwnd
lpOperation, // do not request elevation unless needed
lpFile,
NULL, // no parameters
NULL, // use current working directory
SW_SHOWNORMAL);
if((int)nResult == SE_ERR_ACCESSDENIED)
{
wprintf(L"ShellExecute returned access denied\n");
wprintf(L" Executing the ShellExecute command elevated\n");
nResult = ShellExecute(
NULL,
L"runas", // Trick for requesting elevation
lpFile,
NULL, // no parameters
NULL, // use current working directory
SW_HIDE);
}
if ( (int) nResult < 32) {
wprintf(L" ShellExecute failed with error %d\n", (int) nResult);
return 1;
}
else {
wprintf(L" ShellExecute succeeded and returned value %d\n", (int) nResult);
return 0;
}
}
无线网络配置文件的高级设置
Windows Vista 及更高版本包括一个高级用户界面,用于查看和编辑无线网络配置文件的高级设置。 可以通过调用 WlanUIEditProfile 函数来启动此高级 UI。
相关主题