本文介绍了通过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直接虚拟适配器#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.

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

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 hostednetwork ... 命令进行配置)和新"移动热点在后台使用不同的技术.

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的等待功能,可在此处找到.

$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