Return to Snippet

Revision: 58204
at July 1, 2012 06:24 by Rectifier

Initial Code
@echo off

::Tested on a Windows 7 x64 Home Premium machine, but invoking powrprof.dll should work on any xp/
::server 2k3 machine and higher
::Script by Rectifier 06-30-2012

::You WILL need to manually edit the sleepact label to include programs that interrupt sleep

set choice=
set /p choice="Enter sleep mode? y/n: "
if not "%choice%"=="" set choice=%choice:~0,1%
if /i "%choice%"=="y" goto sleepact
echo Did not choose yes!!!
goto end

::Programs associated with internet traffic are typical culprits for interrupting sleep mode
::Of these programs, p2p file sharing programs such as utorrent definitely interrupt sleep mode
::MCE Standby Tool is a free program to figure out what is potentially blocking/stopping sleep mode

::Uncomment the example taskkill statments to use them!
::The taskkill command works by using the process name, not the name of the application itself

echo Killing off any netprogs!
::taskkill /f /im utorrent.exe > nul 2>&1
::taskkill /f /im mirc.exe > nul 2>&1
::taskkill /f /im xchat.exe > nul 2>&1
::taskkill /f /im Steam.exe > nul 2>&1
::taskkill /f /im firefox.exe > nul 2>&1
::taskkill /f /im chrome.exe > nul 2>&1
::taskkill /f /im iexplore.exe > nul 2>&1
::taskkill /f /im opera.exe > nul 2>&1
echo Sleeping automatically in five seconds!
choice /c:yn /n /t 5 /d y /m "Do you really want to sleep? y/n: "
set slstatus=%ERRORLEVEL%
if "%slstatus%"=="2" (
echo Sleep cancelled.
goto end
) ELSE (
echo ~SLEEP~ | rundll32.exe powrprof.dll,SetSuspendState 0,1,0
goto end

ping -n 2 | find "Reply" > nul
exit /b

Initial URL

Initial Description
This is a fraction of a much larger script which does multiple tasks. This scriptlet is intended to be interactive and somewhat user-friendly. First, it asks if you want to place the computer into sleep mode, then it kills pesky processes associated with interrupting sleep mode, finally, if you want the batch to skip waiting you can press Y to immediately start the sleep sequence or press N to cancel at the last second.

Initial Title
Put windows to sleep (and keep it asleep!)

Initial Tags

Initial Language
DOS Batch