【彻底解决】Win10设置开机自动开启【移动热点】

  • Post author:
  • Post category:其他


1. 在D盘根目录创建wifi.txt记事本,随后粘贴下面内容:

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)
if ($tetheringManager.TetheringOperationalState -eq 1) 
{
    "Hotspot is already On!"
}
else{
    "Hotspot is off! Turning it on"
    Await ($tetheringManager.StartTetheringAsync()) ([Windows.Networking.NetworkOperators.NetworkOperatorTetheringOperationResult])
}

如下图所示:

2.将


wifi.txt


重命名为


wifi.ps1


至此,我们就在D盘根目录下面创建好了这个


wifi.ps1


脚本文件

3. 更改系统策略

由于Windows10系统默认的策略是禁止直接运行ps1脚本文件的,所以需要先修改一下系统策略


右键点击开始按钮>Windows PowerShell(管理员)

执行下面命令:

set-executionpolicy remotesigned

出现策略更改提示后按字母A

4.测试脚本

修改完策略后执行


D:\wifi.ps1


运行我们刚才创建的脚本进行测试,出现


Hotspot is off! Turning it on 代表脚本成功,开始启动热点!

5.设置脚本开机自启动




wifi.ps1


同级目录下建立


wifi.bat


,使用文本编辑打开,输入以下内容,然后保存:

pushd %~dp0
powershell.exe -command ^
  "& {set-executionpolicy Remotesigned -Scope Process; .'.\wifi.ps1' }"
popd
pause




wifi.bat


添加到


开机计划


中即可。




具体可见



win10添加计划任务



6.可重启电脑测试是否正常自动开启热点

文中涉及到的附件,可在下方下载。


附件下载



版权声明:本文为qq_25667815原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。