共用方式為


無線使用者介面 API

Windows 8、Windows Server 2012 及更新版本包含新的連接管理器功能,可讓使用者輕鬆地連線到因特網和其他網路(例如工作和家庭網路)。 這個新的連接管理器功能會取代較舊的 連線到網路,並 管理舊版 Windows 隨附的無線網路 使用者介面,以管理原生 Wifi 連線。

在 Windows 7、Windows Server 2008 和 Windows Vista 上,有許多使用者介面 (UI) 可用來連線或設定無線網路。 這些 UI 可以使用 Native Wifi 和 Windows Shell 函式在應用程式中啟動。 這些 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 函式也可用來啟動 Manage Wireless Networks 專案。 在 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。

使用原生 Wifi

無線配置檔範例

ShellExecute

WlanUIEditProfile