不连接wifi和有限网络如何打开windows热点?
windows10只能连接了某个wifi或者有线网络的时候才能打开热点,下面就用代码强制开启热点(注意:不连WiFi不等于不打开WiFi,要开热点还是要打开WiFi的)
属性
private static NetworkOperatorTetheringManager _networkOperatorTetheringManager;
/// <summary>
/// 网络共享管理对象
/// </summary>
public static NetworkOperatorTetheringManager NetworkOperatorTetheringManager
{
get
{
if (_networkOperatorTetheringManager == null)
{
try
{
_connectionProfile = NetWorkIconHelper.ConnectProfile ?? GetConnectionProfile();
if (_connectionProfile == null)
{
_connectionProfile = GetConnectionProfileFirst();
}
if (_connectionProfile != null)
{
_networkOperatorTetheringManager = NetworkOperatorTetheringManager.CreateFromConnectionProfile(_connectionProfile);
}
}
catch (Exception ex)
{
Log.Debug("_networkOperatorTetheringManager异常");
}
}
return _networkOperatorTetheringManager;
}
}
原理是获取当前连接的适配器,如果当前没有适配器就获取曾经连接过的某个一个适配器进行连接
当前适配器
public static ConnectionProfile GetConnectionProfile()
{
ConnectionProfile connectionProfile = null;
Application.Current.Dispatcher.Invoke(
new Action(() =>
{
connectionProfile = NetworkInformation.GetInternetConnectionProfile();
})
);
return connectionProfile;
}
曾经连结过的适配器(随便随一个,这里选了第一个)
public static ConnectionProfile GetConnectionProfileFirst()
{
ConnectionProfile connectionProfile = null;
Application.Current.Dispatcher.Invoke(
new Action(() =>
{
connectionProfile = NetworkInformation
.GetConnectionProfiles()
?.FirstOrDefault();
})
);
return connectionProfile;
}
打开热点
NetworkOperatorTetheringManager.StartTetheringAsync();
不知道为什么微软不允许这样操作,但是以上是能够在不连接wifi和有线网络情况下开启热点的

浙公网安备 33010602011771号