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 安装Memcached 

1、下载Memcached  版本是Windows 系统 64位的,解压压缩包,然后放到指定的目录下面。 我是直接放在C盘目录下面 ...

Windows 系统 常用软件 官网地址

昨天系统重新安装了,然后百度搜了一下。
百度上搜的都是广告和乱七八糟的网站,下载的还可能是病毒。

所以我收集了常用软件的官网地址,下次安装可以直接下载了。

暂无评论

目录展开