本文介绍了通过 cmd/batch/powershell 启用 Windows 10 内置热点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种通过命令提示符、powershell 或批处理文件启用/禁用内置于 Windows 10 的热点的方法.在 GUI 中,可以使用网络面板中的第三个按钮轻松完成(见下图),但我想将其自动化.

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.

我已经找到了数百篇关于如何使用 netsh创建新的热点的教程,但据我所知,这会创建另一个不同的热点.相反,我想使用已经配置好的.或者,Windows 10 是否每次都使用相同的方法并创建一个新的热点,但中间只记住设置?

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. 我当前的 WiFi 驱动程序不支持托管网络.如果我输入 netsh wlan show drivers,它会显示 hosted network supprt: no.因此,对于通用"解决方案,我必须更新驱动程序.
  2. 不过,我可以使用内置解决方案创建一个 HotSpot(见图).
  3. 似乎如果我激活这个 HotSpot,Windows 会创建一个额外的 Microsoft Wi-Fi Direct Virtual Adapter #x.一旦我停用 HotSpot,适配器就会消失.
  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.

因此,与 netsh 变体相比,MS 似乎对内置热点使用了一种非常不同的技术.这又让我想到了一个问题:如何(通过脚本)自动启用/禁用此热点?

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?

推荐答案

托管网络(可以使用 netsh wlan set hostingnetwork ... 命令进行配置)和新"移动热点在幕后使用不同的技术.

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.

有一个 WinRT API 来控制和配置您所指的新"移动热点.您可以从 PowerShell 调用它:

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

以下代码片段需要 Ben N. 的 PowerShell 中 IAsyncOperation 和 IAsyncAction 的 await 函数,可在此处找到.

$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])

NetworkOperatorTetheringManager 类还允许您以编程方式设置热点的 SSID 和密码.

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

这篇关于通过 cmd/batch/powershell 启用 Windows 10 内置热点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-12 13:49