There are plenty of articles around the Internet discussing how to enable or disable a Wi-Fi adapter based on the status of the wired connection. Whilst I’ve seen that some Dell laptops have this as a simple option in BIOS, our Lenovo machines do not, so this post describes how I achieved a workable solution.
Most modern NIC drivers log an event to the System log when a link is established or disconnected:
This means that it’s possible to create a scheduled task with triggers to look for those specific events, and run a script to enable or disable the wireless adapter.
Some people set up multiple tasks, and multiple scripts, to enable/disable the adapter, but I found it easier to create a single script that runs whenever any of these events occur:
- e1dexpress and e1cexpress – Event ID 32 (Link established)
- e1dexpress and e1cexpress – Event ID 27 (Link disconnected)
- On workstation unlock (useful if the computer is put to sleep, and then un-docked)
- At system startup
Note that the script may not work out-of-the-box if you don’t have a NIC that’s driven by one of the above drivers.
I currently push the script and the scheduled task configuration out using Group Policy Preferences.
Note that this script depends on the network adapters having their default names as per Windows 8.x’s naming. Also, PowerShell 4.0 is required, as the script makes use of the newer *-NetAdapter cmdlets.