我正在寻找一种自动方法来阻止某些时间的任何蓝牙和/或 WiFi 连接。例如,当我的 PC 处于睡眠状态时。
因为微软凭借其无穷的智慧和对用户的服务,让你的睡眠 PC 能够搜索连接,并在你打开耳机使用手机时窃取你的耳机连接……或者你的睡眠 PC 会因为有人碰到蓝牙鼠标而被唤醒。还会耗尽笔记本电脑的电池电量。
基本上需要 Windows 11自动“飞行模式”开关可以通过任务计划程序事件运行。但是 vbs/ahk 中没有“Fn”,据我所知也没有其他快捷键,除非你足够聪明,编写一个“机器人”来静默快速地导航设置菜单
答案1
我想到了一个解决方案,但它没有触及“飞行模式”。希望能有更好的解决方案。
它涉及在 BthServ 和 WlanSvc 上使用net start
and net stop
(带 /Y 和 admin)命令。Martin 是这个问题提到使用net stop bthserv... doesn't actually turn off the radio (Bluetooth speaker continues playing music)
- 但根据我的经验,它有效并且确实停止了所有连接/音乐等。(在 Windows 11 上测试)
只需阅读说明:
:: Stops (or starts) the Bluetooth serivce (BthServ) and the Wifi service (WlanSvc).
:: Name this file "btOnOffBat.bat".
:: Run it as "btOnOffBat.bat -off" (for example as a shortcut or via cmd) (and set it to run as adminitrator), and Windows (and any devices) will no longer be connected.
:: Run it as "btOnOffBat.bat -on" (for example as a shortcut or via cmd), and Windows (and any devices) will automatically reconnect. (for example your wifi, and bluetooth mouse will reconnect)
:: You can also use this .bat in a Task Scheduler task on sleep (or wake) to stop the stupid Windows S3 "hybrid sleep" from keeping your radios on, draining battery, stealing your bt connections, or waking up due to radio connection events, while it is supposed to be sleeping!
:: More info on task scheduler and event codes:
:: Make sure you set the event to "Run with highest privileges".
:: For on Sleep event: Set task to run "On an event" trigger, with Log: System, Source: Power-Troubleshooter, Event ID 42.
:: For on Wake event: Set task to run "On an event" trigger, with Log: System, Source: Power-Troubleshooter, Event ID 1.
:: (The Action is "Start a program", with this .bat file as the target, and the -on or -off argument.)
:: (remember to also (un)tick any other relevant things like running on battery, run before login etc)
@echo off
if "%~1"=="-off" (
net stop bthserv /y
echo Bluetooth bthserv is now OFF.
net stop WlanSvc /y
echo Wifi WlanSvc is now OFF.
) else if "%~1"=="-on" (
net start bthserv /y
echo Bluetooth bthserv is now ON.
net start WlanSvc /y
echo Wifi WlanSvc is now ON.
) else (
echo please specify either -on or -off.
)
exit 0
[编辑] 我在事件日志中发现了:
- “系统正在退出现代待机”事件,日志名称:“系统”,来源:“内核电源”,事件 ID:“507”。我没有看到“1”事件。所以我将调整我的任务调度程序事件并进行更多测试。
- “系统正在进入现代待机状态”,名称:“系统”,来源:“内核电源”,ID:“506”。我没有看到“42”。
[编辑] 坏消息。这个解决方案非常有效,直到你进入(s3)睡眠状态。当你进入睡眠状态时,M$ 会确保所有无线电服务都在运行,如果没有运行,则启动它们。我还尝试禁用任务计划程序任务,手动运行此 bat,进入睡眠状态,无线电打开。检查了事件查看器,不确定我们能做些什么。
通过睡眠解决的解决方案基本上是禁用网络适配器和(不确定是否可以)禁用蓝牙适配器,然后进入睡眠状态...要自动执行此操作,您需要找到适配器的设备 ID。