ConnectionProfile Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Represents a network connection, including the currently connected network or prior connections.
Provides information about connection status and connectivity statistics.
public ref class ConnectionProfile sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class ConnectionProfile final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class ConnectionProfile
Public NotInheritable Class ConnectionProfile
- Inheritance
- Attributes
Windows requirements
| Device family |
Windows 10 (introduced in 10.0.10240.0)
|
| API contract |
Windows.Foundation.UniversalApiContract (introduced in v1.0)
|
Examples
Summarize active internet profile (C#):
using Windows.Networking.Connectivity;
ConnectionProfile profile = NetworkInformation.GetInternetConnectionProfile();
if (profile != null)
{
var level = profile.GetNetworkConnectivityLevel();
var cost = profile.GetConnectionCost();
var plan = profile.GetDataPlanStatus();
bool metered = cost.NetworkCostType != NetworkCostType.Unrestricted || cost.Roaming || cost.OverDataLimit;
// Use 'metered' flag to gate background sync
}
Enumerate usage over last hour (C++/WinRT):
IAsyncAction LogUsage(ConnectionProfile const& profile)
{
auto endTime = DateTime::clock::now();
auto startTime = endTime - std::chrono::hours(1);
NetworkUsageStates states; // default (all)
auto usages = co_await profile.GetNetworkUsageAsync(startTime, endTime, DataUsageGranularity::PerMinute, states);
for (auto const& u : usages)
{
auto bytes = u.BytesSent() + u.BytesReceived();
// Aggregate or log bytes
}
}
Log cost state (C++/WinRT):
void LogCost(ConnectionProfile const& profile)
{
if (!profile) return;
auto cost = profile.GetConnectionCost();
std::wcout << L"CostType=" << static_cast<int>(cost.NetworkCostType())
<< L" roaming=" << (cost.Roaming() ? L"true" : L"false")
<< L" overLimit=" << (cost.OverDataLimit() ? L"true" : L"false")
<< L" approachingLimit" << (cost.ApproachingDataLimit() ? L"true" : L"false")
<< L" backgroundRestricted" << (cost.BackgroundDataUsageRestricted() ? L"true" : L"false")
<< std::endl;
}
Delete a removable Wi-Fi profile if allowed (C#):
using Windows.Networking.Connectivity;
var profiles = await NetworkInformation.FindConnectionProfilesAsync(new ConnectionProfileFilter{ IsWlanConnectionProfile = true });
foreach (var p in profiles)
{
if (p.CanDelete == TriStates.Yes)
{
var status = await p.TryDeleteAsync();
// Check status (Success, DeniedBySystem, UnknownError)
}
}
Query attributed usage for a specific app (C++/WinRT snippet pattern):
IAsyncAction LogAttributedUsage(ConnectionProfile const& profile)
{
if (!profile) co_return;
auto endTime = clock::now();
auto startTime = endTime - std::chrono::minutes(30);
NetworkUsageStates states; // no roaming/shared constraints
// Optional: attribute by a set of host names (e.g., your service endpoints)
std::vector<HostName> hosts{ HostName{ L"api.contoso.com" }, HostName{ L"cdn.contoso.com" } };
auto hostView = single_threaded_vector(std::move(hosts)).GetView();
// Per-app usage
auto appUsages = co_await profile.GetAttributedNetworkUsageAsync(startTime, endTime, states);
for (auto const& u : appUsages)
{
auto total = u.BytesSent() + u.BytesReceived();
// u.AttributionId() identifies the bucket
}
}
Check ___domain authentication mechanism (C#):
using Windows.Networking.Connectivity;
var profile = NetworkInformation.GetInternetConnectionProfile();
if (profile != null)
{
bool isLdap = profile.IsDomainAuthenticatedBy(DomainAuthenticationKind.Ldap);
bool isTls = profile.IsDomainAuthenticatedBy(DomainAuthenticationKind.Tls);
if (isLdap || isTls)
{
// Enable enterprise-only resources; optionally branch on LDAP vs TLS
}
}
Remarks
ConnectionProfile represents a snapshot of a specific network interface's connectivity attributes (WLAN, WWAN, Ethernet, etc.). Re-query the profile when you receive a network status change event because cached profile objects may be obsolete or contain stale properties.
Connectivity level evolution and connection attempts
A single ConnectionProfile instance can progress through LocalAccess, ConstrainedInternetAccess, and
InternetAccess states as the network becomes fully usable. Always call GetNetworkConnectivityLevel at the
decision point instead of assuming the level when the profile was first retrieved.
Important
The network status reported by Windows APIs is only a hint - its accuracy may vary depending on the local network
topology and conditions. Apps should attempt to connect to their services whenever LocalAccess or higher connectivity
is reported.
For a complete implementation demonstrating these principles, see the NetworkConnectivity sample.
Common tasks:
- Determine effective connectivity level (GetNetworkConnectivityLevel).
- Inspect data plan and metering (GetConnectionCost, GetDataPlanStatus).
- Get adapter and network names (NetworkAdapter, ProfileName).
- Retrieve per-profile usage statistics (GetNetworkUsageAsync, GetAttributedNetworkUsageAsync).
- Identify WLAN SSID (WlanConnectionProfileDetails.GetConnectedSsid) or WWAN home/roaming state (WwanConnectionProfileDetails).
- Determine if the profile can be deleted (for example, a user-saved Wi-Fi profile) via
CanDelete/TryDeleteAsync.
Cost / data usage considerations:
- Respect metered networks: If
connectionCost.NetworkCostTypeis notNetworkCostType.Unrestricted, delay large background transfers unless the user initiates them. - If
connectionCost.Roamingistrue, avoid non-critical sync to prevent unexpected charges. - If
connectionCost.OverDataLimitorconnectionCost.ApproachingDataLimitis set, surface a UI warning or reduce quality (for example, lower bitrate streaming).
Deletion guidance:
TryDeleteAsync succeeds only for user-removable profiles (for example, some WLAN profiles) and when the caller has
appropriate permissions. Always check the returned ConnectionProfileDeleteStatus and handle DeniedBySystem or
UnknownError gracefully.
Performance tips:
- Avoid calling usage APIs (GetNetworkUsageAsync) too frequently; aggregate intervals (for example, per 15 minutes) for telemetry.
- Dispose of large usage collections promptly; enumerate and summarize rather than storing raw entries.
- For background tasks, check cost state late (immediately before transfer) to ensure freshness.
Interoperability note: Classic desktop components may still use NLM (INetworkListManager) or DUSM cost APIs directly; the WinRT surface (ConnectionProfile, NetworkInformation) abstracts these for most app scenarios.
Independent cost flag changes:
- Flags such as
Roaming,OverDataLimit, orApproachingDataLimitmay change whileNetworkCostTyperemains constant. Re-evaluate individual flags when behavior depends on them; do not rely solely onNetworkCostTypetransitions.
Domain authentication:
Some enterprise networks can be ___domain-authenticated via classic Active Directory (LDAP) or via a TLS-based mechanism
configured through device management policy. Use IsDomainAuthenticatedBy with DomainAuthenticationKind.Ldap or
DomainAuthenticationKind.Tls to differentiate the method. Only one method reports true (LDAP takes precedence when
both could succeed). Treat IsDomainAuthenticatedBy returning DomainAuthenticationKind.None as "not ___domain
authenticated". Re-query after network status change events rather than caching earlier results because authentication
state can change with network transitions.
Relationship to DomainConnectivityLevel:
GetDomainConnectivityLevel reports the broader ___domain trust state (None / Unauthenticated / Authenticated) while
IsDomainAuthenticatedBy identifies which mechanism (LDAP or TLS) established that trust. Typically you first
ensure GetDomainConnectivityLevel returns Authenticated and then branch on the authentication kind if you need to
distinguish behavior or telemetry.
For more examples, see the NetworkConnectivity sample.
Version history
| Windows version | SDK version | Value added |
|---|---|---|
| 1709 | 16299 | GetProviderNetworkUsageAsync |
| 1809 | 17763 | CanDelete |
| 1809 | 17763 | TryDeleteAsync |
Properties
| CanDelete |
Gets a value that indicates whether or not it is possible to delete this connection profile. This can help determine whether TryDeleteAsync is likely to succeed. |
| IsWlanConnectionProfile |
Gets a value that indicates if connection profile is a WLAN (WiFi) connection. This determines whether or not WlanConnectionProfileDetails is null. |
| IsWwanConnectionProfile |
Gets a value that indicates if connection profile is a WWAN (mobile) connection. This determines whether or not WwanConnectionProfileDetails is null. |
| NetworkAdapter |
Gets the object representing the network adapter providing connectivity for the connection. |
| NetworkSecuritySettings |
Retrieves the security settings for the network. |
| ProfileName |
Gets the name of the connection profile. |
| ServiceProviderGuid |
Gets the ID of the network operator who provisioned the connection profile. |
| WlanConnectionProfileDetails |
Gets a WlanConnectionProfileDetails object that provides a method for retrieving information specific to a WLAN (WiFi) connection. |
| WwanConnectionProfileDetails |
Gets a WwanConnectionProfileDetails object containing the properties and methods used to retrieve information specific to mobile broadband connections. |
Methods
| GetAttributedNetworkUsageAsync(DateTime, DateTime, NetworkUsageStates) |
Retrieves per-attribution (application or bucket) usage (bytes sent / received and connected duration) over a specified time window with optional NetworkUsageStates filtering. |
| GetConnectionCost() |
Gets the cost information for the connection. |
| GetConnectivityIntervalsAsync(DateTime, DateTime, NetworkUsageStates) |
Retrieves connectivity intervals (start timestamp plus duration) for this profile within the specified time window. |
| GetDataPlanStatus() |
Gets the current status of the data plan associated with the connection. |
| GetDomainConnectivityLevel() |
Gets the current ___domain authentication status for a network connection. Possible values are defined by DomainConnectivityLevel. |
| GetLocalUsage(DateTime, DateTime, RoamingStates) |
Note GetLocalUsage may be altered or unavailable for releases after Windows 8.1. Instead, use GetNetworkUsageAsync. Gets the estimated data usage for a connection over a specific period of time and roaming state. |
| GetLocalUsage(DateTime, DateTime) |
Note GetLocalUsage may be altered or unavailable for releases after Windows 8.1. Instead, use GetNetworkUsageAsync. Gets the estimated data usage for a connection during a specific period of time. |
| GetNetworkConnectivityLevel() |
Gets the network connectivity level for this connection. This value indicates what network resources, if any, are currently available. |
| GetNetworkNames() |
Retrieves names associated with the network with which the connection is currently established. |
| GetNetworkUsageAsync(DateTime, DateTime, DataUsageGranularity, NetworkUsageStates) |
Retrieves per-interval usage (bytes sent/received and connected duration) for this profile over a specified time window using the requested DataUsageGranularity and optional NetworkUsageStates filters. |
| GetProviderNetworkUsageAsync(DateTime, DateTime, NetworkUsageStates) |
Returns the bytes sent and bytes received for each MCC and MNC combination (the combination is represented by a ProviderId). |
| GetSignalBars() |
Gets a value that indicates the current number of signal bars displayed by the Windows UI for the connection. |
| IsDomainAuthenticatedBy(DomainAuthenticationKind) |
Determines whether the specified ___domain authentication mechanism succeeded for this connection profile. |
| TryDeleteAsync() |
Asynchronously attempts to delete this connection profile; the operation may or may not succeed. Examine the return value to determine the outcome of the operation. |