Skip to main content

休眠wifi蓝牙失效问题

方法1

来源:https://www.cnblogs.com/kamigao/p/11706008.html

在Windows从休眠或睡眠模式唤醒以重新启动WLAN AutoConfig服务之后,我编写了一个简单的PowerShell脚本,以管理员权限运行:

$WLANProc = Get-CimInstance Win32_Process | Where-Object {$_.CommandLine -eq "c:\windows\system32\svchost.exe -k LocalSystemNetworkRestricted -p"}
Stop-Process -Id $WLANProc.ProcessId -Force
Start-Service WlanSvc

您可能还需要重新启动Wi-Fi适配器:

restart-netadapter -InterfaceDescription 'your_wireless_adapter_name' -Confirm:$false

您可以由Windows自动触发事件运行脚本,通过它的代码绑定到一个事件1电源故障诊断系统日志源(此事件出现在日志中从休眠或睡眠唤醒后)。

这是后一种方法,它帮助我解决了Windows 10中从睡眠状态唤醒后丢失Wi-Fi网络连接的问题。

方法2

开启ps的脚本功能

Set-ExecutionPolicy Unrestricted

创建三个脚本文件

1.bat

@echo off
powershell -command C:\BlueTeethReboot\1.ps1 -BluetoothStatus Off
choice /t 1 /d y /n >nul
powershell -command C:\BlueTeethReboot\1.ps1 -BluetoothStatus On

1.ps1

[CmdletBinding()] Param (
[Parameter(Mandatory=$true)][ValidateSet('Off', 'On')][string]$BluetoothStatus
)
If ((Get-Service bthserv).Status -eq 'Stopped') { Start-Service bthserv }
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
}
[Windows.Devices.Radios.Radio,Windows.System.Devices,ContentType=WindowsRuntime] | Out-Null
[Windows.Devices.Radios.RadioAccessStatus,Windows.System.Devices,ContentType=WindowsRuntime] | Out-Null
Await ([Windows.Devices.Radios.Radio]::RequestAccessAsync()) ([Windows.Devices.Radios.RadioAccessStatus]) | Out-Null
$radios = Await ([Windows.Devices.Radios.Radio]::GetRadiosAsync()) ([System.Collections.Generic.IReadOnlyList[Windows.Devices.Radios.Radio]])
$bluetooth = $radios | ? { $_.Kind -eq 'Bluetooth' }
[Windows.Devices.Radios.RadioState,Windows.System.Devices,ContentType=WindowsRuntime] | Out-Null
Await ($bluetooth.SetStateAsync($BluetoothStatus)) ([Windows.Devices.Radios.RadioAccessStatus]) | Out-Null

1.vbs

set ws=WScript.CreateObject("WScript.Shell")

ws.Run "c:\1.bat",0

建立计划任务

每当用户登录时,触发1.vbs脚本,创建完成,然后右键》属性》勾选使用最高权限运行、隐藏

效果:用户在登录时候自动关闭1秒后重启蓝牙模块。 导致用户在系统登录之初蓝牙掉线,但是恢复速度很快,总体掉线时间一般不会超过2秒。 对于苏菲这种非性能笔记本来说这点时间我还是等得起的。

优点:用户锁屏时候不会运行此脚本,而是在用户注销或者重启机器时候运行。

修改注册表

亲测有效后,一段时间后失效

reg add HKLM\System\CurrentControlSet\Control\Power /v PlatformAoAcOverride /t REG_DWORD /d 0
reg add HKLM\System\CurrentControlSet\Control\Power /v PlatformAoAcOverride /t REG_DWORD /d 1 
# 把值改1就恢复,改0睡眠鼠标键盘不能唤醒,要关机重启。

方法3