Looking for sleep timer that closes programs too

drambit

Distinguished
Sep 23, 2011
59
1
18,545
I like to leave white noise playing for about an hour or so as I go to sleep every night. Right now my options are either leaving my computer running all night, or set a sleep timer so that my computer goes to sleep at a specific time every night. The latter option sounds good, but what I often find is that it sleeps my computer in the middle of a video, and when it does that drivers mess up, causing my computer to bluescreen on wakeup.

Is there a way to set up a timed sleep that closes programs before sleeping? Looking specifically for something I can set to "Go to sleep in one hour, close programs first, doesn't sleep until programs are closed."
 
Solution
That powercfg -h off and powercfg -h on lines should cause hibernation to be disabled.
one possibility is that said changes might need admin command prompt and as such you would have to run the batch file with admin privileges.

Alternately, you could skip a bit of it like mentioned in 2nd link:
Download the http://technet.microsoft.com/en-us/sysinternals/bb897541.aspx tool by SysInternals. Using this tool, you will be able to make the PC enter sleep mode directly by giving a single command:

psshutdown.exe -d -t 0 -accepteula

I recommend PsShutdown as the preferred way to send a PC to sleep.
I don't know of a simple way to do it but.. batch file could do it.

You can kill off program(s) that are running with:
http://tweaks.com/windows/39559/kill-processes-from-command-prompt/

They list how to make computer go to sleep:
http://winaero.com/blog/how-to-sleep-windows-10-from-the-command-line/

and you can add timeout so that it takes that hour (3600 seconds) until it kills stuff:
https://technet.microsoft.com/en-us/library/cc754891(v=ws.11).aspx

So.. in essence, build a batch file like this:
Code:
rem ** Give it 3600 seconds until it starts to kill the process playing your white noise, the > NUL disables output count in the prompt**
Timeout /t 3600 > NUL
rem ** Kills all processes with name of firefox.exe, if this is not correct, you should change it.
Taskkill /IM firefox.exe /F
rem ** Waits 10 seconds more so that firefox is "dead" This taskkill is not clean closing but.. it wont cause driver issues.
Timeout /t 10 > NUL
rem ** Turns hibernation off, this is in here in case you have it enabled in power options, otherwise the line is pointless and should be removed
powercfg -h off
rem ** causes computer to go to sleep, alternately, if computer has low idle to sleep timer like 5 to 10 mins, you could just leave this line out too and allow it to sleep on it's own.
rundll32.exe powrprof.dll,SetSuspendState 0,1,0
rem ** turns hibernation back on once computer wakes from sleep, this should be here only if you have hibernation on in the first place, otherwise it should be removed.
powercfg -h on
 

drambit

Distinguished
Sep 23, 2011
59
1
18,545


I made a batch file out of that, and it seemed to work as intended, but I got a x116 bluescreen on wakeup again. This problem is so weird, I put my computer to sleep every night, and wake it up in the morning with no problems, but if it sleeps while watching a video I get bluescreened. The batch file is set to close chrome and then wait 15 seconds before sleeping and it still bluescreened, I have no idea why.

 
There are two things that might be possible problems:
Something else is running also
Timeout between killing off chrome and sleep might be too short. It might take longer for it to die off and video drivers to abandon the idea.

You could try the batch file with shorter initial duration (2 to 5 mins instead of whole hour) and just kill of chrome while looking at task manager to see how long it takes for it to die off properly and if something else is left.
for that something else, you can just add another taskkill line to kill that too, identifying it first is the problem though.
 

drambit

Distinguished
Sep 23, 2011
59
1
18,545


I checked my minidumps and took a picture of a bluescreen error, turns out its atikmpag.sys causing me troubles. I wiped every trace of video drivers off I computer that I could find and reinstalled them perfectly clean in safe mode, still getting the same bluescreen error though on wakeup from timed sleep. What's extra weird is that if I'm watching a video, and select sleep mode while watching, I can wake my computer back up and continue watching without any trouble, but if I use the batch file or windows timed sleep or any other method, when I turn my computer back on it has to POST, like it is hibernating, but I specifically turned hybrid sleep off. After POST it tries to resume windows and then bluescreens. I really have no idea what to do.

 
I have no idea either, past the batch file way of killing off processes and putting computer to sleep, I have no other real idea about it.

General google solutions seem to be reinstalling/updating video card drivers but... you already did that and it didn't fix issues, also if drivers were the issue, it should do same on manual sleep too.
 

drambit

Distinguished
Sep 23, 2011
59
1
18,545


It only does it on hibernate for some reason, I think that batch file causes the computer to hibernate, not sleep. Every time I put my computer in hibernate in bluescreens on wakeup with the same error. Having trouble fixing that but I suppose this is not the forum for that.


 
That powercfg -h off and powercfg -h on lines should cause hibernation to be disabled.
one possibility is that said changes might need admin command prompt and as such you would have to run the batch file with admin privileges.

Alternately, you could skip a bit of it like mentioned in 2nd link:
Download the http://technet.microsoft.com/en-us/sysinternals/bb897541.aspx tool by SysInternals. Using this tool, you will be able to make the PC enter sleep mode directly by giving a single command:

psshutdown.exe -d -t 0 -accepteula

I recommend PsShutdown as the preferred way to send a PC to sleep.
 
Solution

TRENDING THREADS