既に登録されているプロファイル中の無線LANに接続する方法を記載します。
以下説明は、”Managed Wifi”を使用して行います。
プロファイル中の無線LANに接続をする
Imports NativeWifi
Dim targetInterface = "Wi-Fi" 'ワイヤレス ネットワーク接続";
Dim targetProfile = "XXXXXXXXXXXXX-2G"
Dim client As WlanClient = New WlanClient()
'先頭のインタフェースを取得する
Dim wlanIface = client.Interfaces().Where(Function(x) x.InterfaceName = targetInterface).FirstOrDefault()
If wlanIface Is Nothing Then
Return
End If
'プロファイルが存在するかチェックする
Dim profile = (From x In wlanIface.GetProfiles() Where x.profileName = targetProfile Select x.profileName).FirstOrDefault()
If profile Is Nothing Then
Return
End If
'インタフェースの接続状態をチェック
If wlanIface.InterfaceState = Wlan.WlanInterfaceState.Connected Then
'接続中のプロファイル名が接続したいプロファイル名と一致するかチェック
If wlanIface.CurrentConnection.profileName = targetProfile Then
Return
End If
End If
'接続を開始する
wlanIface.Connect(Wlan.WlanConnectionMode.Profile, Wlan.Dot11BssType.Any, targetProfile)