Windows 11 开机自动启动移动热点

才发现带WiFi的主板可以当路由器用。😂

1)修改Windows策略

使用Windows PowerShell 执行set-executionpolicy remotesigned

set-executionpolicy remotesigned

如果要恢复策略,则执行set-executionpolicy restricted命令行

2)创建bat文件

在C:UsersChengAppDataRoamingMicrosoftWindowsStart MenuProgramsStartup文件路径下创建一个pondsihotspot.bat文件,并输入下面的命令行

powershell -executionpolicy remotesigned -file "C:UsersChengAppDataRoamingMicrosoftWindowsStart MenuProgramsStartuppondsihotspot.ps1"
exit

3)创建PS1文件

可以在其他文件夹下创建一个pondsihotspot.ps1文件,只要bat文件路径对的就行。

输入下面的代码

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) {
""
}
else{
Await ($tetheringManager.StartTetheringAsync()) ([Windows.Networking.NetworkOperators.NetworkOperatorTetheringOperationResult])
}

然后重启查看移动热点是否开启



知识共享许可协议本作品采用知识共享署名-相同方式共享 4.0 国际许可协议进行许可。

相关推荐

Windows 11 安装python

1)下载python 2)安装python 打开安装包,执行安装 cmd输入python 本作品采用知识共享署 ...

暂无评论

目录展开