带有无线网卡设备的Windows10系统中提供了移动热点的功能,可以很方便的将电脑有线网络通过无线广播出去(相当于无线路由器的效果),但是这个功能必须要手动开启,下面提供一个可以开机自动开启移动热点的方法.
右键点击开始按钮>运行,运行下面命令:
notepad d:\开启热点.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])
}
记事本保存并关闭
至此,我们就在D盘根目录下面创建好了这个开启热点.ps1
脚本文件.
测试脚本
由于Windows10系统默认的策略是禁止直接运行ps1脚本文件的,所以需要先修改一下系统策略
右键点击开始按钮>Windows PowerShell(管理员)
执行下面命令:
set-executionpolicy remotesigned
出现策略更改提示后按字母a
修改完策略后执行d:\开启热点.ps1
运行我们刚才创建的脚本进行测试
设置脚本开机自启动
右键点击开始按钮>运行>shell:startup
在打开的启动
文件夹空白处点击鼠标右键>新建>快捷方式
对象位置处填写powershell d:\开启热点.ps1
点击下一步后快捷方式命名为开启热点
,点击完成按钮
收工
至此设置完毕,重启一下系统看看效果吧