1

I am looking for an automatic way to prevent any Bluetooth and/or WiFi connections during certain times. E.g. while my PC is asleep.

Because Microsoft in its infinite wisdom and user servitude, has made it so that your sleeping PC will hunt for connections, and steal your headphone connection when you're turning them on to use them with your phone… Or your sleeping PC will wake because someone bumped a Bluetooth mouse. Also will drain battery for laptops.

Essentially need a Windows 11 auto “Airplane Mode” switch that can be run via Task Scheduler events. But There's no "Fn" in vbs / ahk, and no other shortcuts afaik unless you're clever enough to script a "bot" to silently & quickly navigate the settings menu 👍☹️.

There are various networking ways you can try that don't work. For example the PowerShell/app method doesn't work because you need to digitally sign your script/app or else it's not secure/allowed.

I'd especially like to control the “Airplane Mode” / "Flight Mode". Everything else changes across updates or is not reliable (e.g. windows turns it back on).

I could do a Task Scheduler task to run "On an event" trigger, with Log: System, Source: Power-Troubleshooter, Event ID 42 (for sleep) and Event ID 1 (for wake). Hopefully these event codes still work with modern standby. But what script to run?

3
  • In Device Manager > Network Adapters > adapter_name (right-click) > properties > Power Management Tab, is "Allow the computer to turn off this device to save power" on for the network adapter?
    – harrymc
    Commented Jan 21 at 17:30
  • @harrymc The Network adapter does not have a Power tab. The Bluetooth adapter does have it, and that option was already checked. But more importantly: "allow to save power" does not equal "always 100% keep it off under all circumstances" ---- I tested and after 8h of sleep I could instantly wake my pc with a bluetooth mouse, even though the bluetooth adapter had the save power checked. M$ is stubborn to say the least. Commented Jan 22 at 11:02
  • I think you need to use combination of bios config and windows power plan reconfiguration, also you need info on S and C-states if you dont have them. (techjunkie.com/power-management-states-s-state-p-state). In other words, in my opinion, your windows are doing exactly what they were set to do by default, normal behavior when device is idle, specially with devices that are up to 5years old.
    – Danijel
    Commented Jan 22 at 12:19

1 Answer 1

1

I figured out one solution but it does not touch “Airplane Mode.” Would love a better solution.

It involves using the net start and net stop (with /Y and admin) commands on the BthServ and WlanSvc. Martin, the asker of this question mentioned that using net stop bthserv... doesn't actually turn off the radio (Bluetooth speaker continues playing music) -- but in my experience it works and does stop all connections / music etc. (tested on windows 11)

Just read the instructions:

:: 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

[EDIT] I caught in the Event Log:

  • "The system is exiting Modern Standby" event, with Log Name: "System", Source: "Kernel-Power", Event ID: "507". And I didn't see a "1" event. So I'll tweak my task scheduler events and test some more.
  • "The system is entering Modern Standby" with Name: "System", Source: "Kernel-Power", ID: "506". And I didn't see a "42".

[EDIT] Bad news. This solution works perfectly, until you go to (s3) sleep. When you sleep, M$ makes sure all radio services are running and starts them if they aren't. I also tried to disable the task scheduler tasks, run this bat manually, go to sleep, and radios were on. Checked the event viewer, not sure we can do anything about it.

A solution that would work through sleep is to basically Disable the network adapter and (not sure if you can) Disable the bluetooth adapter, and then go to sleep... To automate this, you'd need to find the device IDs for the adapters.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .