How to disallow USB devices to wake the computer by default in Windows 7
Every time I plug in a new mouse/keyboard or plug an existing one to a new USB port, I have to manually go to the device manager, go to the device's property page, and uncheck "Allow this device to wake the computer" on the "Power Management" page.
Is it possible to set up a system policy in Windows 7, such that this box is not checked for new USB mice/keyboards by default?
Edit: If there's no way to set up such a system policy, is there at least a way to enumerate and disable USB wake on devices by using powercfg
in a batch file?
Edit 2: This has to be possible to do at least using powercfg
. powercfg devicequery wake_armed
gives a list of all devices that can wake the system. Now how can I feed this list back to powercfg
and have it disable the wake on the listed devices?
Edit 2: Clarification
This answer does not solve the problem in question in its original wording. Disabling wake for all future devices does not seem to be possible. The solution in this answer only allows you to disable wake for all currently connected devices.
My original answer:
This question seems to have been answered in another SO answer
for /F "tokens=*" %%A in ('powercfg -devicequery wake_armed') do powercfg -devicedisablewake "%%A"
This needs to be run as an administrator.
Edit:
To provide a more complete solution here is a script that requests administrator privileges before running the above loop. The admin rights are requested using a Microsoft powertoy (written in VisualBasic, unsurprisingly)
@echo off
if "%~1"=="" (
elevate %0 do
) else if "%~1"=="do" (
for /F "tokens=*" %%A in ('powercfg -devicequery wake_armed') do (
if not "%%A"=="NONE" (
echo Disabling %%A
powercfg -devicedisablewake "%%A"
)
)
echo All done.
pause
) else (
echo Usage: %~nx0
)
[DISCLAIMER] This is not an answer to the OP question but rather a solution to the problem for which you probably ended up here!
Old thread but I came here firstly for a solution which I ended up resolving in another way and now I'm sharing.
[ISSUE] My issue was with an USB device (xbox controller) keeping the PC awake or waking it up as soon as it entered sleep. At first I ended up needing to do what OP was talking about, after that I gave SnaKe script a try.
[SOLUTION] It was solved properly without any hacky scripts or manual controls just by configuring XHCI in bios setting it from SmartAuto to Enabled.
[BITS OF WHY] What this does is forcing the USB on board controller to act as USB3 all the time rather than downgrading to USB2 and then switching to USB3 when OS takes control. Forcing it to behave proven to have solved my issue with the USB device driver misbehaving when trying to transition the PC into sleep/hibernate. Running Windows 10 which has built in drivers for USB3 enabling XHCI mode works greatly, issues may come from forcing it if booting some OS that doesn't have support for USB3.
SmartAuto shouldn't have been an issue to start with because (as stated here) after the first bootup of the computer the controller should stay on USB3 (acting as Enabled) but maybe there is a bug somewhere in it's logic or how sleep state get's considered by the feature and it was behaving as Auto on my Asus motherboard .
To answer the questions in your edits:
No, you can not use powercfg to enumerate devices to change the default wake behaviour of all future USB configurations like you asked in your original question.
I tried using the For /F "tokens=*" %%A in ('powercfg -devicequery wake_armed') do powercfg -devicedisablewake "%%A"
script, but after plugging my USB device into a new port, it defaulted back to waking the computer.
I even tried enumerating the result of powercfg -devicequery wake_from_any
, but it seems that you can only enumerate connected USB devices. Even the wake_from_any
argument returns a different list each time you change the port your USB device is plugged into.
To to answer your original question:
I have no idea. I really want to know the answer to this, but I still haven't found an answer. If anyone can figure this out, you will be loved dearly! <3