问题
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 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 via netsh, but as I understand it this would create another, different hotspot. Instead I want to use the already configured one. Or does Win10 the same and everytime creates a new hotspot but in between only memories the settings?
Thanks in advance,
Sebastian
Edit:
I played around a little bit and discovered the following:
- my current WiFi driver doesnt support hosted networks. If I enter
netsh wlan show drivers
it sayshosted network supprt: no
. So for the 'common' solution I would had to update the driver. - nevertheless I can create a HotSpot with the inbuild solution (see image).
- 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 inbuild hotspot than the netsh variant. Which brings me again to the question: how can I automate (by script) the enabling/disabling of this hotspot?
回答1:
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.
回答2:
I think the only solution at the moment is to setup an autohotkey script to click the button on start up. Windows +A, Shift Tab, down arrow, etc... I need this for a headless PC to allow wifi remote desktop.
回答3:
The Windows 10 mobile hotspot gets started by the Windows Mobile Hotspot Service (icssvc). Using Powershell:
Get the current state of the service:
get-service "icssvc"
Start the service:
start-service "icssvc"
Stop the service:
stop-service "icssvc"
If you want to configure the hotspot then thats another thing. You can Google "Configure Internet Connection Sharing with PowerShell" to get you started.
回答4:
Turn on command - netsh wlan set hostednetwork mode=allow
Turn off command - netsh wlan set hostednetwork mode=disallow
-not tested-
回答5:
By Using CMD. It is too Simple to turn PC as Hotspot. But you PC must have Hosted network supported, to check it out try this command
@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
来源:https://stackoverflow.com/questions/45833873/enable-win10-inbuild-hotspot-by-cmd-batch-powershell