通过cmd / batch / powershell启用Win10 inbuild热点

时间:2017-08-23 07:56:38

标签: windows powershell batch-file cmd hotspot

正如标题所示,我通过命令提示符/ powershell /批处理文件搜索在Win10中启用/禁用Hotspot inbuild的方法。在GUI中,可以使用网络面板中的第三个按钮轻松完成(参见下图),但我希望自动化它。

我已经找到了一些教程如何通过netsh创建一个新的热点,但据我所知,这将创建另一个不同的热点。 相反,我想使用已配置的一个。或者Win10是否相同,每次创建一个新的热点,但只在记忆之间设置?

提前致谢,

塞巴斯蒂安

编辑:

我玩了一下,发现了以下内容:

  1. 我目前的WiFi驱动程序不支持托管网络。如果我输入netsh wlan show drivers,则会显示hosted network supprt: no。所以对于常见的'我不得不更新驱动程序。
  2. 尽管如此,我可以使用inbuild解决方案创建一个HotSpot(见图)。
  3. 似乎如果我激活此HotSpot窗口会创建一个额外的Microsoft Wi-Fi Direct Virtual Adapter #x。一旦我停用HotSpot,适配器就会消失。
  4. 因此,对于内置热点,MS似乎使用了与netsh变体完全不同的技术。这让我再次回答这个问题:如何自动(通过脚本)启用/禁用此热点?

8 个答案:

答案 0 :(得分:2)

基于the PowerShell comment above

以下是用于混合/匹配的WinRT代码组件,以使用C ++完成WiFi Direct 2.0 HotSpot活动的上述任务,而无需依赖其他工具等(它们在IoT Core等上工作):

  • 以编程方式设置 SSID 和/或 PassPhrase
  • 以编程方式查询当前的WiFi Direct 2.0热点状态
  • 以编程方式打开/关闭 WiFi Direct 2.0热点
#include <winrt/Windows.Networking.Connectivity.h>
#include <winrt/Windows.Networking.NetworkOperators.h>
namespace winrt { // /ZW embed in :<winrt> when `Windows` is ambiguously defined
  static void af_winrt_wifi_hotspot_test() {
    // start ms-settings:network-mobilehotspot
    init_apartment(); // apartment_type::multi_threaded
    auto connectionProfile { Windows::Networking::Connectivity::NetworkInformation::GetInternetConnectionProfile() };
    auto tetheringManager = Windows::Networking::NetworkOperators::NetworkOperatorTetheringManager::CreateFromConnectionProfile(connectionProfile);
    switch(tetheringManager.TetheringOperationalState()) {
      case Windows::Networking::NetworkOperators::TetheringOperationalState::Off: {
          auto ioAsync = tetheringManager.StartTetheringAsync();
          auto fResult = ioAsync.get();
        }
        break;
      case Windows::Networking::NetworkOperators::TetheringOperationalState::On: {
          auto ioAsync = tetheringManager.StopTetheringAsync();
          auto fResult = ioAsync.get();
        }
        break;
      case Windows::Networking::NetworkOperators::TetheringOperationalState::InTransition:
      default:
        break;
    }
    clear_factory_cache();
    uninit_apartment();
  }
}

答案 1 :(得分:2)

TL;DR:
如果有人感兴趣,我已经使用上述解决方案创建了一个批处理文件来打开移动热点。只需创建一个新的 .bat 文件并将以下代码粘贴到其中:

@echo off
powershell.exe -encodedCommand WwBXAGkAbgBkAG8AdwBzAC4AUwB5AHMAdABlAG0ALgBVAHMAZQByAFAAcgBvAGYAaQBsAGUALgBMAG8AYwBrAFMAYwByAGUAZQBuACwAVwBpAG4AZABvAHcAcwAuAFMAeQBzAHQAZQBtAC4AVQBzAGUAcgBQAHIAbwBmAGkAbABlACwAQwBvAG4AdABlAG4AdABUAHkAcABlAD0AVwBpAG4AZABvAHcAcwBSAHUAbgB0AGkAbQBlAF0AIAB8ACAATwB1AHQALQBOAHUAbABsAA0ACgBBAGQAZAAtAFQAeQBwAGUAIAAtAEEAcwBzAGUAbQBiAGwAeQBOAGEAbQBlACAAUwB5AHMAdABlAG0ALgBSAHUAbgB0AGkAbQBlAC4AVwBpAG4AZABvAHcAcwBSAHUAbgB0AGkAbQBlAA0ACgAkAGEAcwBUAGEAcwBrAEcAZQBuAGUAcgBpAGMAIAA9ACAAKABbAFMAeQBzAHQAZQBtAC4AVwBpAG4AZABvAHcAcwBSAHUAbgB0AGkAbQBlAFMAeQBzAHQAZQBtAEUAeAB0AGUAbgBzAGkAbwBuAHMAXQAuAEcAZQB0AE0AZQB0AGgAbwBkAHMAKAApACAAfAAgAD8AIAB7ACAAJABfAC4ATgBhAG0AZQAgAC0AZQBxACAAJwBBAHMAVABhAHMAawAnACAALQBhAG4AZAAgACQAXwA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gAjACAAUwB0AGEAcgB0ACAATQBvAGIAaQBsAGUAIABIAG8AdABzAHAAbwB0AA0ACgBBAHcAYQBpAHQAIAAoACQAdABlAHQAaABlAHIAaQBuAGcATQBhAG4AYQBnAGUAcgAuAFMAdABhAHIAdABUAGUAdABoAGUAcgBpAG4AZwBBAHMAeQBuAGMAKAApACkAIAAoAFsAVwBpAG4AZABvAHcAcwAuAE4AZQB0AHcAbwByAGsAaQBuAGcALgBOAGUAdAB3AG8AcgBrAE8AcABlAHIAYQB0AG8AcgBzAC4ATgBlAHQAdwBvAHIAawBPAHAAZQByAGEAdABvAHIAVABlAHQAaABlAHIAaQBuAGcATwBwAGUAcgBhAHQAaQBvAG4AUgBlAHMAdQBsAHQAXQApAA==

(虽然说起来很琐碎,但我会提醒你,上面的代码也可以作为 CMD 命令工作)。

说明:
我所做的是采用以下 PowerShell 脚本(由 Julius Hardt 在上述答案中给出),并使用 this 转换器将其转换为批处理文件:

[Windows.System.UserProfile.LockScreen,Windows.System.UserProfile,ContentType=WindowsRuntime] | Out-Null
Add-Type -AssemblyName System.Runtime.WindowsRuntime
$asTaskGeneric = ([System.WindowsRuntimeSystemExtensions].GetMethods() | ? { $_.Name -eq 'AsTask' -and $_.GetParameters().Count -eq 1 -and $_.GetParameters()[0].ParameterType.Name -eq 'IAsyncOperation`1' })[0]
Function Await($WinRtTask, $ResultType) {
    $asTask = $asTaskGeneric.MakeGenericMethod($ResultType)
    $netTask = $asTask.Invoke($null, @($WinRtTask))
    $netTask.Wait(-1) | Out-Null
    $netTask.Result
}
Function AwaitAction($WinRtAction) {
    $asTask = ([System.WindowsRuntimeSystemExtensions].GetMethods() | ? { $_.Name -eq 'AsTask' -and $_.GetParameters().Count -eq 1 -and !$_.IsGenericMethod })[0]
    $netTask = $asTask.Invoke($null, @($WinRtAction))
    $netTask.Wait(-1) | Out-Null
}
$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])

我还将此批处理文件放在位于 "C:\Users\\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup" 的启动文件夹中,所以移动热点将在 Windows 启动时自动打开。



要打开/关闭移动热点,我已将上述答案(通过 Julius Hardt)修改为:

[Windows.System.UserProfile.LockScreen,Windows.System.UserProfile,ContentType=WindowsRuntime] | Out-Null
Add-Type -AssemblyName System.Runtime.WindowsRuntime
$asTaskGeneric = ([System.WindowsRuntimeSystemExtensions].GetMethods() | ? { $_.Name -eq 'AsTask' -and $_.GetParameters().Count -eq 1 -and $_.GetParameters()[0].ParameterType.Name -eq 'IAsyncOperation`1' })[0]
Function Await($WinRtTask, $ResultType) {
    $asTask = $asTaskGeneric.MakeGenericMethod($ResultType)
    $netTask = $asTask.Invoke($null, @($WinRtTask))
    $netTask.Wait(-1) | Out-Null
    $netTask.Result
}
Function AwaitAction($WinRtAction) {
    $asTask = ([System.WindowsRuntimeSystemExtensions].GetMethods() | ? { $_.Name -eq 'AsTask' -and $_.GetParameters().Count -eq 1 -and !$_.IsGenericMethod })[0]
    $netTask = $asTask.Invoke($null, @($WinRtAction))
    $netTask.Wait(-1) | Out-Null
}

$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

# If Mobile Hotspot is on - turn it off.
if ($tetheringManager.TetheringOperationalState -eq 1){
    # Stop Mobile Hotspot
    Await ($tetheringManager.StopTetheringAsync()) ([Windows.Networking.NetworkOperators.NetworkOperatorTetheringOperationResult])
}
# If Mobile Hotspot is off - turn it on.
else{
    # Start Mobile Hotspot
    Await ($tetheringManager.StartTetheringAsync()) ([Windows.Networking.NetworkOperators.NetworkOperatorTetheringOperationResult])
}


对应的批处理文件:

@echo off
powershell.exe -encodedCommand WwBXAGkAbgBkAG8AdwBzAC4AUwB5AHMAdABlAG0ALgBVAHMAZQByAFAAcgBvAGYAaQBsAGUALgBMAG8AYwBrAFMAYwByAGUAZQBuACwAVwBpAG4AZABvAHcAcwAuAFMAeQBzAHQAZQBtAC4AVQBzAGUAcgBQAHIAbwBmAGkAbABlACwAQwBvAG4AdABlAG4AdABUAHkAcABlAD0AVwBpAG4AZABvAHcAcwBSAHUAbgB0AGkAbQBlAF0AIAB8ACAATwB1AHQALQBOAHUAbABsAA0ACgBBAGQAZAAtAFQAeQBwAGUAIAAtAEEAcwBzAGUAbQBiAGwAeQBOAGEAbQBlACAAUwB5AHMAdABlAG0ALgBSAHUAbgB0AGkAbQBlAC4AVwBpAG4AZABvAHcAcwBSAHUAbgB0AGkAbQBlAA0ACgAkAGEAcwBUAGEAcwBrAEcAZQBuAGUAcgBpAGMAIAA9ACAAKABbAFMAeQBzAHQAZQBtAC4AVwBpAG4AZABvAHcAcwBSAHUAbgB0AGkAbQBlAFMAeQBzAHQAZQBtAEUAeAB0AGUAbgBzAGkAbwBuAHMAXQAuAEcAZQB0AE0AZQB0AGgAbwBkAHMAKAApACAAfAAgAD8AIAB7ACAAJABfAC4ATgBhAG0AZQAgAC0AZQBxACAAJwBBAHMAVABhAHMAawAnACAALQBhAG4AZAAgAC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lAHQAdwBvAHIAawBPAHAAZQByAGEAdABvAHIAcwAuAE4AZQB0AHcAbwByAGsATwBwAGUAcgBhAHQAbwByAFQAZQB0AGgAZQByAGkAbgBnAE8AcABlAHIAYQB0AGkAbwBuAFIAZQBzAHUAbAB0AF0AKQANAAoAfQANAAoADQAKAA==

答案 2 :(得分:1)

Windows 10移动热点由Windows移动热点服务(icssvc)启动。 使用Powershell:

获取服务的当前状态:

get-service "icssvc"

启动服务:

start-service "icssvc"

停止服务:

stop-service "icssvc"

如果要配置热点,那就另当别论了。您可以通过Google“使用PowerShell配置Internet连接共享”来开始使用。

答案 3 :(得分:1)

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

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

以下代码段需要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])

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

答案 4 :(得分:1)

我可以确认@smallscript的winRT解决方案有效。运行脚本将根据当前状态打开/关闭热点连接(启用为禁用,反之亦然)。

为了完成他的回答,我将指出另外两点以便编译代码:

  • 您必须安装Windows SDK(我使用版本10.0.18362.0)才能拥有winRT库。
  • 您需要将RuntimeObject.lib库链接到您的项目,否则您将获得未解析的外部符号(使用VS,将名称添加到:项目->属性->链接器->输入->其他依赖项)

答案 5 :(得分:0)

我认为目前唯一的解决方案是设置一个autohotkey脚本,点击启动时的按钮。 Windows + A,Shift Tab,向下箭头等...我需要这个用于无头PC以允许wifi远程桌面。

答案 6 :(得分:-1)

使用CMD。 把PC变成Hotspot太简单了。但是你的PC必须支持托管网络,要检查出来试试这个命令

    @echo off
REM    Copyright (C) 2013  
REM    user49828
REM
REM    Batch file for creating Wifi Hotspot
if _%1_==_payload_  goto :payload

:getadmin
    echo %~nx0: elevating self
    set vbs=%temp%\getadmin.vbs
    echo Set UAC = CreateObject^("Shell.Application"^)                >> "%vbs%"
    echo UAC.ShellExecute "%~s0", "payload %~sdp0 %*", "", "runas", 1 >> "%vbs%"
    "%temp%\getadmin.vbs"
    del "%temp%\getadmin.vbs"
goto :eof

:payload
    echo %~nx0: running payload with parameters:
    echo %*
    echo ---------------------------------------------------
    cd /d %2
    shift
    shift
    rem put your code here
    rem e.g.: perl myscript.pl %1 %2 %3 %4 %5 %6 %7 %8 %9
    :start
@ECHO off
ECHO  Pleae select one of the options Programmed By Overflown.com  "user49828"
ECHO  --------------------------------------------------------------------------------------------------------------------------
ECHO  1 Hotspot settings
ECHO  2 Start Hotspot
ECHO  3 Stop  Hotspot
ECHO  --------------------------------------------------------------------------------------------------------------------------

SET /p option=Please enter one of the options:

if %option%==1  ( goto setup )      else set /a er=1
if %option%==2  ( goto start1 )      else set /a er=er+1
if %option%==3  ( goto stop )       else set /a er=er+1

:noOption
if %er% GEQ 3 ( 
Echo Error!
Echo Please enter a correct option
@pause
cls  
goto start
)

:setup
SET /p ssid=Please enter the Hotspot name:
SET /p key=Please enter the Hotspot password greater the 8 digits:
netsh wlan set hostednetwork mode=allow ssid=%ssid% key=%key% 
if %errorlevel%==0 (
ECHO Setup complete
)
@pause
cls  
goto start

:start1
netsh wlan start hostednetwork
@pause
cls  
goto start

:stop
netsh wlan stop hostednetwork
@pause
cls  
goto start
goto :eof

答案 7 :(得分:-1)

启用命令 - netsh wlan set hostednetwork mode = allow

关闭命令 - netsh wlan set hostednetwork mode = disallow

- 未经测试 -