[UWP]私人/家庭网络上的Windows PC [英] [UWP]Windows PC on Private/Home Network

查看:97
本文介绍了[UWP]私人/家庭网络上的Windows PC的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们如何在UWP开发(XAML和C#)中检查Windows 10 PC是否在私人/家庭网络上连接?此外,打开设置以从公共网络切换到专用/家庭网络?

How can we check whether a Windows 10 PC is connected on Private/Home network in UWP development (XAML and C#)? Also, open settings to switch from Public network to Private/Home network?

谢谢

推荐答案

Hi Shivin Shrivastava,

Hi Shivin Shrivastava,

据我所知,没有办法获取有关Windows 10 PC是否在UWP中的私人/家庭网络上连接的信息。

As I known, there is no method to get the info about whether a Windows 10 PC is connected on Private/Home network in UWP.

形成图像,似乎您通过WiFi连接网络。作为解决方法,我们应该能够在您的应用中保存专用网络的ssid。我们可以使用  WiFiAdapter.FindAllAdaptersAsync  静态
方法或  WiFiAdapter.ScanAsync  方法。您还可以通过获取  AvailableNetworks   WiFiAdapter.NetworkReport 。 

Form the image, it seems you connect the network by WiFi. As a workaround, we should able to save the ssid of private network in your app. That we can initiate a network scan using the WiFiAdapter.FindAllAdaptersAsync static method or the WiFiAdapter.ScanAsync method on a particular adapter. You can also retrieve the list of networks from the results of the most current scan from a given Wi-Fi adapter by getting the AvailableNetworks property of the WiFiAdapter.NetworkReport. 

有关详细信息,请参阅  < a href ="https://msdn.microsoft.com/en-us/library/windows/apps/xaml/windows.devices.wifi.wifiavailablenetwork.aspx"> WiFiAvailableNetwork   class。

For more info, see WiFiAvailableNetwork class.

我们可以使用  WlanConnectionProfileDetails.GetConnectedSsid  获取
使用的连接ssid   WlanConnectionProfileDetails.GetConnectedS sid等于  AvailableNetwork.Ssid。如果connectedSSid等于它在私人/家庭网络上连接的专用网络ssid。

And we can use WlanConnectionProfileDetails.GetConnectedSsid to get the connected ssid that use the WlanConnectionProfileDetails.GetConnectedSsid equals to the AvailableNetwork.Ssid. If the connectedSSid equals to the private network ssid that it connected on Private/Home network.

例如:

string connectedSsid = null;

string privateNetworkSsid =" xxxxxxx" ;;

var connectedProfile = await adapter.NetworkAdapter.GetConnectedProfileAsync();
if(connectedProfile!= null&&
connectedProfile.IsWlanConnectionProfile&&
connectedProfile.WlanConnectionProfileDetails!= null)
{
connectedSsid = connectedProfile.WlanConnectionProfileDetails .GetConnectedSsid();
}

if(!string.IsNullOrEmpty(connectedSsid))
{
if(connectedSsid.Equals(AvailableNetwork.Ssid))
{
if(connectedSSid.Equals(privateNetworkSsid))

string privateNetworkSsid= "xxxxxxx"; var connectedProfile = await adapter.NetworkAdapter.GetConnectedProfileAsync(); if (connectedProfile != null && connectedProfile.IsWlanConnectionProfile && connectedProfile.WlanConnectionProfileDetails != null) { connectedSsid = connectedProfile.WlanConnectionProfileDetails.GetConnectedSsid(); } if (!string.IsNullOrEmpty(connectedSsid)) { if (connectedSsid.Equals(AvailableNetwork.Ssid)) { if(connectedSSid.Equals(privateNetworkSsid))

{

//私网连接

}
}
}

} } }

您可以在Wi-Fi扫描示例中获取更详细的代码:  https://github.com/Microsoft/Windows-universal-samples/tree/e13cf5dca497ad661706d150a154830666913be4/Samples/WiFiScan

You can get the more detail code in Wi-Fi scanning sample: https://github.com/Microsoft/Windows-universal-samples/tree/e13cf5dca497ad661706d150a154830666913be4/Samples/WiFiScan.

我在桌面上找不到设置页面,有一个关于如何从你的应用程序启动Windows设置应用程序的文档。请在此链接中查看: https://msdn.microsoft .com / zh-CN / windows / uwp / launch-resume / launch-settings-app

I can not find the setting page in my desktop, there is a document about how to launch the Windows Settings app from your app. Please refer it in this link: https://msdn.microsoft.com/en-us/windows/uwp/launch-resume/launch-settings-app.

最好的问候,

Jayden Gu 

Jayden Gu 


这篇关于[UWP]私人/家庭网络上的Windows PC的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆