🔥 Win11 Hotspot Service | 热点自启与保活

告别手动开启热点,开机静默运行,断线自动巡检重连。

🚀 方法一:极速一键部署 (Quick Install) 强烈推荐

适合所有用户。自动完成目录创建、核心脚本生成、注册表自启项写入,并在后台自动拉起热点服务。

操作步骤: 鼠标右键点击屏幕底部的 Windows 开始按钮,选择 终端(管理员)PowerShell(管理员),复制并执行下方命令。
* 注:为避免 PowerShell 编码导致中文乱码,终端部署进度将以纯英文 (English) 输出。

📦 一键安装命令 (Install Command)

irm https://yourdomain.pages.dev/install.ps1 | iex

🗑️ 一键卸载命令 (Uninstall Command)

如果不再需要自动开热点,以管理员身份运行下方命令即可彻底无痕清除:

irm https://yourdomain.pages.dev/uninstall.ps1 | iex

🛠️ 方法二:手动逐步配置 (Manual Setup) 备用方案

如果你更喜欢自己动手控制细节,或者网络无法远程拉取脚本,可按照以下步骤手动配置。

第一步:创建专属脚本文件夹

PowerShell(管理员) 中运行以下命令,自动在系统目录创建空脚本:

New-Item -ItemType Directory -Path "C:\Program Files\HotspotService" -Force; New-Item -ItemType File -Path "C:\Program Files\HotspotService\hotspot.ps1" -Force

第二步:写入核心心跳保活代码

用记事本打开 C:\Program Files\HotspotService\hotspot.ps1,将下方完整代码复制进去并保存关闭:

$logFile = "C:\Program Files\HotspotService\log.txt"

# Clear old log on startup
Remove-Item -Path $logFile -Force -ErrorAction SilentlyContinue
Start-Sleep -Seconds 15

function Write-Log($message) {
    $time = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
    "[$time] $message" | Out-File $logFile -Append -Encoding ascii
}

Write-Log "=== Hotspot Keep-Alive Heartbeat Service Started ==="

try {
    $netType = [Windows.Networking.Connectivity.NetworkInformation, Windows.Networking.Connectivity, ContentType=WindowsRuntime]
    $pickerType = [Windows.Networking.NetworkOperators.NetworkOperatorTetheringManager, Windows.Networking.NetworkOperators, ContentType=WindowsRuntime]
} catch {
    Write-Log "[FATAL] Failed to load WinRT libraries: $_"
}

while ($true) {
    try {
        $profile = $netType::GetInternetConnectionProfile()
        if ($null -ne $profile) {
            $manager = $pickerType::CreateFromConnectionProfile($profile)
            $manager.StartTetheringAsync() | Out-Null
            Write-Log "Heartbeat: Tethering activation enforced successfully."
        } else {
            Write-Log "[WARNING] Internet profile is null. Waiting..."
        }
    } catch {
        Write-Log "[ERROR] Loop exception: $_"
    }
    Start-Sleep -Seconds 180
}

第三步:配置后台静默自启

继续在 PowerShell(管理员) 中执行以下完整代码,生成后台 VBS 引导壳并配置注册表:

# 生成 launch.vbs 隐藏运行窗口
$vbsContent = @'
Set WshShell = CreateObject("WScript.Shell")
WshShell.Run "powershell.exe -NoProfile -ExecutionPolicy Bypass -File ""C:\Program Files\HotspotService\hotspot.ps1""", 0, False
'@
$vbsContent | Out-File "C:\Program Files\HotspotService\launch.vbs" -Encoding ascii

# 写入注册表自启项
Set-ItemProperty -Path "HKLM:\Software\Microsoft\Windows\CurrentVersion\Run" -Name "AutoHotspot" -Value 'wscript.exe "C:\Program Files\HotspotService\launch.vbs"'

Write-Host ">>> 手动配置完成!你可以重启电脑测试了。<<<" -ForegroundColor Green

🧰 进阶调试与排查指令 (Troubleshooting)

测试过程中如果遇到系统权限限制或进程问题,可使用以下常用排查命令:

1. 一键杀光后台所有脚本进程 (Kill Processes)

cmd /c taskkill /f /im powershell.exe /im wscript.exe

2. 解除当前用户的 PowerShell 脚本运行限制 (Unlock Execution Policy)

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Force