1
I got fed up with my PC waking from sleep apparently at random intervals and did all the usual stuff, disabling wake timers, task schedules, disallowing LAN and other devices, running powercfg /sleepstudy etc. to no avail.
I found some scripts to disable all wake timers and ran that:
Get-ScheduledTask | ? { $_.Settings.WakeToRun -eq $true -and $_.State -ne "Disabled"} | % { $_.Settings.WakeToRun = $false; Set-ScheduledTask $_ }
Unfortunately, I also ran a script to disallow any device to wake the PC which appears to stall the sleep command until a key press and then shuts it down completely:
(/F "tokens=*" %A in ('powercfg -devicequery wake_armed') do powercfg -devicedisablewake "%A"
This produces several errors.
Although I can understand much of it, I don't have the programming skills to write a script to correct it :-(
Can anybody on here help? (can't restore a system image at the moment - I lent my backup drive+caddy to a buddy who's away)(OK - I'm a Muppett)
EDIT:
OK - I ran
PS C:\WINDOWS\system32> @echo off
for /F "tokens=*" %%A in ('powercfg -devicequery wake_armed') do (powercfg -devicedisablewake "%%A")
which gave an error of a missing '(' after keyword 'for'. So, I put one in:
PS C:\WINDOWS\system32> @echo off for (/F "tokens=*" %%A in ('powercfg -devicequery wake_armed') do (powercfg -devicedisablewake "%%A").
This appears to have worked, although I still don't understand why, because there appears to be one '(' too many.
EDIT 2 Is there a way to reverse it? Can I just replace -devicedisableawake with -deviceenablewake ?
2What are the "several errors" it produces? – Mokubai – 2018-02-18T19:29:29.457
@Mokubai
do was unexpected at this time.
:) – DavidPostill – 2018-02-18T19:43:19.637One error was "F : The term '/F' is not recognized as the name of a cmdlet, function, script file, or operable program". Also, the original script had no ( at the start. Windows Powershell Admin said there was a missing ( at the start of the script, I didn't follow that because the ( made it unbalanced. I put one in and the script ran without an error - weird. – birchyboy – 2018-02-19T09:28:59.710
Another error was - The splatting operator '@' cannot be used to reference variables in an expression. '@echo' can be used only as an argument to a command. To reference variables in an expression use '$echo'. – birchyboy – 2018-02-19T09:48:40.430