windows10/11设置移动热点自启(图文步骤教程)

1,546 阅读2分钟

windows10/11设置移动热点自启(图文步骤教程).md

1、在D盘根目录创建wifi1.txt记事本,随后粘贴下面内容:并重命名为wifi.ps1

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、再创建一个创建wifi2.txt记事本,随后粘贴下面内容:并重命名wifi.bat

powershell.exe -command ^ "& {set-executionpolicy Remotesigned -Scope Process; .'.\wifi.ps1' }"

这样D盘根目录下就有这两个文件wifi.ps1,wifi.bat了

image.png

3、修改系统策略(重要,不然执行不了ps1文件)

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

按快捷键win+Q调起搜索(电脑左下角有个放大镜搜索图标就是)输入:

powershell

出现搜索列表,找到应用 Windows PowerShell 选>以管理员身份运行

弹出以下窗口,复制粘贴下面命令,回车,根据提示打个Y,回车确定即可。

set-executionpolicy remotesigned

4、测试运行wifi.bat文件能不能运行并开启移动热点。

(1)先创建一个快捷键到桌面去运行:

选中文件wifi.bat,鼠标右键,选择--发送到--桌面快捷方式

这样,桌面就有一个快捷方式:

(2)运行测试:先确保关闭电脑的移动热点,点击运行桌面的wifi.bat - 快捷方式,有个黑色的框框一闪而过不见了,再看下热点开了没。

5、最后一步,添加到电脑自启中

打开我的电脑(此电脑),在地址栏输入:

C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup

进入开始菜单的启动文件夹,把桌面的  wifi.bat - 快捷方式  剪切(就是剪切),放进启动文件夹里.

然后,重启下电脑,进入桌面后,等待运行一下。有个黑色框框运行一闪而过之后。看下热点开了没。开了就完事了。

​ 写在最后:
有需要可加交流群交流交流(631689215)交流群