enable Win10 inbuild hotspot by cmd/batch/powershell

前端 未结 7 1947
渐次进展
渐次进展 2020-12-31 10:59

as the title says I search for a way to enable/disable the Hotspot inbuild in Win10 via the command prompt/powershell/a batch file. In the GUI it can be easily done with the

7条回答
  •  独厮守ぢ
    2020-12-31 11:28

    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.

提交回复
热议问题