Share via


NetworkInformation.GetInternetConnectionProfile メソッド

定義

ローカル コンピューターで現在使用されている優先インターフェイス 関連付けられている接続プロファイルを取得します。 推奨されるインターフェイスは、インターネット トラフィックを送受信する可能性が最も高いインターフェイスです。 つまり、返されるプロファイルがインターネットにアクセスできる場合もあれば、インターネットにアクセスできない場合もあります。

public:
 static ConnectionProfile ^ GetInternetConnectionProfile();
 static ConnectionProfile GetInternetConnectionProfile();
public static ConnectionProfile GetInternetConnectionProfile();
function getInternetConnectionProfile()
Public Shared Function GetInternetConnectionProfile () As ConnectionProfile

戻り値

優先インターフェイスに関連付けられている接続プロファイル。適切な接続を持つ接続プロファイルがない場合は null

注釈

接続の変更を通知するには、 ハンドラーを NetworkStatusChanged イベントに 登録します。 ネットワーク状態の変更の通知を受信したら、 GetInternetConnectionProfile メソッドを呼び出して現在の接続プロファイルを取得し、必要に応じて後で使用するために格納できます。

次の例では、 ConnectionProfile を取得する方法を示します。 この関数は GetInternetConnectionProfile を 呼び出して、現在インターネット接続に使用されている可能性が最も高い接続を表す ConnectionProfile を取得します。 または、アプリで GetConnectionProfiles を呼び出して、デバイスで使用可能なすべての接続を取得することもできます。

注意

以下のコードの GetConnectionProfileInfo メソッドの実装と、接続プロファイルを取得するために NetworkInformation クラス メソッドを実装する方法の追加の例については、「 クイック スタート: ネットワーク接続情報の取得」を参照してください。

using Windows.Networking.Connectivity;

// Retrieve the ConnectionProfile.
ConnectionProfile internetConnectionProfile = NetworkInformation.GetInternetConnectionProfile();

// Pass the returned object to a function that accesses the connection data.
string connectionProfileInfo = GetConnectionProfileInfo(internetConnectionProfile);
#include <winrt/Windows.Networking.Connectivity.h>
using namespace winrt;

std::wstring GetConnectionProfileInfo(Windows::Networking::Connectivity::ConnectionProfile const& connectionProfile)
{
    ...
}

int main()
{
    winrt::init_apartment();

    // Retrieve the ConnectionProfile.
    auto internetConnectionProfile{ Windows::Networking::Connectivity::NetworkInformation::GetInternetConnectionProfile() };

    // Pass the returned object to a function that accesses the connection data.
    std::wstring strConnectionProfileInfo{ GetConnectionProfileInfo(internetConnectionProfile) };
}
using namespace Windows::Networking::Connectivity;

// Retrieve the ConnectionProfile.
ConnectionProfile^ internetConnectionProfile = NetworkInformation::GetInternetConnectionProfile();

// Pass the returned object to a function that accesses the connection data.
String^ strConnectionProfileInfo = GetConnectionProfileInfo(internetConnectionProfile);

現在、複数の接続プロファイルがコンピューターをインターネットに接続している場合は、このメソッドによって優先プロファイルが返されます。 優先プロファイルは、インターネットとの間でトラフィックを送受信するときに使用される可能性が最も高い接続を表します。

適用対象