C#
[C#] Enable Windows 10 Mobile HotSpot
Dongmin Jang
2022. 6. 14. 19:38
아래 동작은 모바일 핫스팟에 적용이 안됨
netsh wlan set hostednetwork mode=allow ssid=YOUR_NETWORK_NAME key=YOUR_PASSWORD
Windows Runtime(WinRT)를 적용해야 함
적용법: Netcore3.0~ 또는 Net6.0으로 Nuget Package Microsoft.Windows.SDK.Contracts 적용
소스:
public class MobileHotSpot
{
public static async void Start()
{
var connectionProfile = NetworkInformation.GetInternetConnectionProfile();
var tethering = NetworkOperatorTetheringManager.CreateFromConnectionProfile(connectionprofile);
if (tethering.TetheringOperationalState == TetheringOperationalState.On)
{
Console.WriteLine("Mobile hotspot is enabled");
return;
}
Console.WriteLine("Start mobile hotspot");
await tethering.StartTetheringAsync();
}
public static async void Stop()
{
var connectionProfile = NetworkInformation.GetInternetConnectionProfile();
var tethering = NetworkOperatorTetheringManager.CreateFromConnectionProfile(connectionprofile);
if (tethering.TetheringOperationalState == TetheringOperationalState.Off)
{
Console.WriteLine("Mobile hotspot is disabled");
return;
}
Console.WriteLine("Stop mobile hotspot");
await tethering.StopTetheringAsync();
}
}