Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enable Windows 10 built-in hotspot by cmd/batch/powershell

I'm searching for a way to enable/disable the Hotspot built into Windows 10 via the command prompt, powershell or a batch file. In the GUI, it can be easily done with the third button in the network panel (see image below), but I want to automate it.

I already found some hundred tutorials how to create a new hotspot using netsh, but as I understand it this would create another, different hotspot. Instead I want to use the already configured one. Or does Windows 10 use the same and creates a new hotspot every time but in between only remembers the settings?


I played around a little bit and discovered the following:

  1. My current WiFi driver doesn't support hosted networks. If I enter netsh wlan show drivers it says hosted network supprt: no. So for the 'common' solution I would have to update the driver.
  2. Nevertheless, I can create a HotSpot with the built-in solution (see image).
  3. It seems that if I activate this HotSpot, Windows creates an additional Microsoft Wi-Fi Direct Virtual Adapter #x. As soon I deactivate the HotSpot, the adapter vanishes.

So it seems that MS is using a very different technique for the built-in hotspot than the netsh variant. Which brings me again to the question: how can I automate (by script) the enabling/disabling of this hotspot?

like image 904
casiosmu Avatar asked Aug 23 '17 07:08

casiosmu


People also ask

How do I force my hotspot on Windows 10?

Select the Start button, then select Settings > Network & Internet > Mobile hotspot. For Share my Internet connection from, choose the Internet connection you want to share. Select Edit > enter a new network name and password > Save. Turn on Share my Internet connection with other devices.

How can I create hotspot in my laptop using CMD?

While in Command Prompt (Admin) enter the following command: NETSH WLAN set hostednetwork mode=allow ssid=Your_SSID key=Your_Passphrase Where the SSID would be the name you want to identify your wireless network when trying to connect a new device, and the passphrase is the network security key you want users to use to ...

Why can't I turn on my hotspot on Windows 10?

Open Settings by pressing Win + X keys and choosing Settings on the menu. In Settings, go to Network & Internet > Mobile hotspot. Make sure that your mobile hotspot is on. Then, click Change adapter options under the Related Settings.


1 Answers

The Hosted Network (which can be configured using the netsh wlan set hostednetwork ... command) and the "new" Mobile Hotspot use different technologies under the hood.

There's a WinRT API to control and configure the "new" mobile hotspot you're referring to. You can call it from PowerShell:

The following code snippet requires Ben N.'s await function for IAsyncOperation and IAsyncAction in PowerShell, which can be found here.

$connectionProfile = [Windows.Networking.Connectivity.NetworkInformation,Windows.Networking.Connectivity,ContentType=WindowsRuntime]::GetInternetConnectionProfile()
$tetheringManager = [Windows.Networking.NetworkOperators.NetworkOperatorTetheringManager,Windows.Networking.NetworkOperators,ContentType=WindowsRuntime]::CreateFromConnectionProfile($connectionProfile)

# Be sure to include Ben N.'s await for IAsyncOperation:
# https://superuser.com/questions/1341997/using-a-uwp-api-namespace-in-powershell

# Check whether Mobile Hotspot is enabled
$tetheringManager.TetheringOperationalState

# Start Mobile Hotspot
Await ($tetheringManager.StartTetheringAsync()) ([Windows.Networking.NetworkOperators.NetworkOperatorTetheringOperationResult])

# Stop Mobile Hotspot
Await ($tetheringManager.StopTetheringAsync()) ([Windows.Networking.NetworkOperators.NetworkOperatorTetheringOperationResult])

The NetworkOperatorTetheringManager class also allows you to set the SSID and the passphrase of your hotspot programmatically.

like image 137
Julius Hardt Avatar answered Sep 23 '22 20:09

Julius Hardt