Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save thenewguy/975b30d251a884f0e8892713d004e6a6 to your computer and use it in GitHub Desktop.
Save thenewguy/975b30d251a884f0e8892713d004e6a6 to your computer and use it in GitHub Desktop.
Script to Enable Windows 10 Mobile Hotspot Automatically After Reboot

Enable Windows 10 Mobile Hotspot Automatically After Reboot

❤️ Sponsor This Project

On Windows 10, the Mobile Hotspot feature is automatically disabled when rebooting the machine. Users are required to manually open the Mobile Hotspot settings and toggle the slider for "Share my Internet connection with other devices" in order to enable it.

The included PowerShell script can be added to the Windows Task Scheduler to automatically turn on your Windows 10 Mobile Hotspot upon reboot, login, and unlock of the workstation by any user.

Quick Start

  1. Copy the two script files to a folder on your computer: hotspot.ps1 and hotspot.bat
  2. Open the Windows Task Scheduler.
  3. Right-click on Task Scheduler Library and select Create Task.
    • Enter a Name and Description.
    • Select Run whether user is logged on or not.
    • Checkmark Run with highest privileges.
  4. Click the Triggers tab.
  5. Click New.
    • For Begin the task select At startup.
    • Checkmark Delay task for: 1 minute.
    • Checkmark Stop task if it runs longer than: 30 minutes.
    • Checkmark Enabled.
  6. Click the Conditions tab.
  7. Uncheck the options Stop if the computer switches to battery power and Start the task only if the computer is on AC power.
  8. Click OK.

When saving the Task Scheduler, enter your username (username, ADUser\username, CORP\username, etc.) and your Windows password.

Troubleshooting Hotspot Not Activating After Sleep/Hibernation

If the hotspot enable task is not running after your PC wakes from sleep/hibernation, you can add a trigger to execute the task as soon as possible after waking. Create an additional trigger with the following steps.

  1. Edit the task and click the Triggers tab.
  2. For Begin the task select On a schedule.
  3. Check the radio option Daily.
  4. Enter the earliest Start Time to run. For example, 8:00 AM EST. This computer does not need to be awake during this time, so it is recommended to make this time earlier than you actually need.
  5. Select Recur every 1 day.
  6. Click OK.
  7. Click the Settings tab.
  8. Checkmark the option Run task as soon as possible after a scheduled start is missed.

Troubleshooting Hotspot Disabling Frequently

See also Windows 10 Mobile Hotspot Keep Alive Script.

If the mobile hotspot is turning itself off at random periods, you can try the following settings:

  1. Disable mobile hotspot power saving by opening the Mobile Hotspot settings and disabling When no devices are connected, automatically turn off mobile hotspot.

  2. Set the PeerlessTimeoutEnabled and PublicConnectionTimeout value to a longer duration. This can be done by setting the registry value HKLM\System\ControlSet001\Services\ICSSVC\Settings\PeerlessTimeoutEnabled to 120 (Hexadecimal) and HKLM\System\ControlSet001\Services\ICSSVC\Settings\PublicConnectionTimeout to 60 (Hexadecimal).

    An example registry script is shown below.

    Windows Registry Editor Version 5.00
    
    [HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\icssvc\Settings]
    "PeerlessTimeoutEnabled"=dword:00000120
    "PublicConnectionTimeout"=dword:00000060
    
  3. Run the script hotspot-keep-alive.ps1.

Running the Task When Connecting to the Internet Network

You may optionally want to add a condition to run the task whenever you connect to the Internet. This may be done by adding a new "Trigger" to the task scheduler. Select On an event, for "Log" select Microsoft-Windows-NetworkProfile/Operational, for Source select NetworkProfile, for Event ID enter 10000 (enter 10001 for network disconnect instead of connect). Checkmark Delay task for and select 30 seconds.

Windows 10 Mobile Hotspot Keep Alive Script

An easy script to keep the Windows 10 mobile hotspot turned on even if it becomes disabled.

Windows 10 Mobile Hotspot Keep Alive Script

# https://superuser.com/a/1434648
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
}
Function Get_TetheringManager() {
$connectionProfile = [Windows.Networking.Connectivity.NetworkInformation,Windows.Networking.Connectivity,ContentType=WindowsRuntime]::GetInternetConnectionProfile()
$tetheringManager = [Windows.Networking.NetworkOperators.NetworkOperatorTetheringManager,Windows.Networking.NetworkOperators,ContentType=WindowsRuntime]::CreateFromConnectionProfile($connectionProfile)
return $tetheringManager;
}
Function SetHotspot($Enable) {
$tetheringManager = Get_TetheringManager
if ($Enable -eq 1) {
if ($tetheringManager.TetheringOperationalState -eq 1)
{
"Hotspot is already On!"
}
else{
"Hotspot is off! Turning it on"
Await ($tetheringManager.StartTetheringAsync()) ([Windows.Networking.NetworkOperators.NetworkOperatorTetheringOperationResult])
}
}
else {
if ($tetheringManager.TetheringOperationalState -eq 0)
{
"Hotspot is already Off!"
}
else{
"Hotspot is on! Turning it off"
Await ($tetheringManager.StopTetheringAsync()) ([Windows.Networking.NetworkOperators.NetworkOperatorTetheringOperationResult])
}
}
}
# Define a function to check the status of the hotspot
Function Check_HotspotStatus() {
$tetheringManager = Get_TetheringManager
return $tetheringManager.TetheringOperationalState -eq "Off"
}
# Define a function to start the hotspot
Function Start_Hotspot() {
$tetheringManager = Get_TetheringManager
Await ($tetheringManager.StartTetheringAsync()) ([Windows.Networking.NetworkOperators.NetworkOperatorTetheringOperationResult])
}
$currentDateTime = Get-Date -Format "MM-dd-yyyy HH:mm:ss"
"$currentDateTime Starting hotspot keep-alive."
# Keep alive wifi.
while ($true) {
# Get the current date and time in a specific format
$currentDateTime = Get-Date -Format "MM-dd-yyyy HH:mm:ss"
if (Check_HotspotStatus) {
"$currentDateTime Hotspot is off! Turning it on"
Start_Hotspot
}
Start-Sleep -Seconds 10 # Wait for 10 seconds before checking again
}
PowerShell -Command "Set-ExecutionPolicy Unrestricted" >> "%TEMP%\StartupLog.txt" 2>&1
PowerShell C:\Users\YOUR_USERNAME\Desktop\hotspot.ps1 >> "%TEMP%\StartupLog.txt" 2>&1
# https://superuser.com/a/1434648
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
}
Function SetHotspot($Enable) {
$connectionProfile = [Windows.Networking.Connectivity.NetworkInformation,Windows.Networking.Connectivity,ContentType=WindowsRuntime]::GetInternetConnectionProfile()
$tetheringManager = [Windows.Networking.NetworkOperators.NetworkOperatorTetheringManager,Windows.Networking.NetworkOperators,ContentType=WindowsRuntime]::CreateFromConnectionProfile($connectionProfile)
if ($Enable -eq 1) {
if ($tetheringManager.TetheringOperationalState -eq 1)
{
"Hotspot is already On!"
}
else{
"Hotspot is off! Turning it on"
Await ($tetheringManager.StartTetheringAsync()) ([Windows.Networking.NetworkOperators.NetworkOperatorTetheringOperationResult])
}
}
else {
if ($tetheringManager.TetheringOperationalState -eq 0)
{
"Hotspot is already Off!"
}
else{
"Hotspot is on! Turning it off"
Await ($tetheringManager.StopTetheringAsync()) ([Windows.Networking.NetworkOperators.NetworkOperatorTetheringOperationResult])
}
}
}
Function ToggleHotspot($Delay) {
SetHotspot(1)
sleep -seconds $Delay
SetHotspot(0)
sleep -seconds $Delay
SetHotspot(1)
}
ToggleHotspot(3)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment