Posted By

Rectifier on 07/01/12


Tagged

windows batch dos sleep Hibernate suspend taskkill


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

ionman


Put windows to sleep (and keep it asleep!)


 / Published in: DOS Batch
 

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.

  1. @echo off
  2. @cls
  3.  
  4. ::Tested on a Windows 7 x64 Home Premium machine, but invoking powrprof.dll should work on any xp/
  5. ::server 2k3 machine and higher
  6. ::Script by Rectifier 06-30-2012
  7.  
  8. ::You WILL need to manually edit the sleepact label to include programs that interrupt sleep
  9.  
  10. :sleepcheck
  11. set choice=
  12. set /p choice="Enter sleep mode? y/n: "
  13. if not "%choice%"=="" set choice=%choice:~0,1%
  14. if /i "%choice%"=="y" goto sleepact
  15. echo Did not choose yes!!!
  16. goto end
  17.  
  18. ::Programs associated with internet traffic are typical culprits for interrupting sleep mode
  19. ::Of these programs, p2p file sharing programs such as utorrent definitely interrupt sleep mode
  20. ::MCE Standby Tool is a free program to figure out what is potentially blocking/stopping sleep mode
  21.  
  22. ::Uncomment the example taskkill statments to use them!
  23. ::The taskkill command works by using the process name, not the name of the application itself
  24.  
  25. :sleepact
  26. echo Killing off any netprogs!
  27. ::taskkill /f /im utorrent.exe > nul 2>&1
  28. ::taskkill /f /im mirc.exe > nul 2>&1
  29. ::taskkill /f /im xchat.exe > nul 2>&1
  30. ::taskkill /f /im Steam.exe > nul 2>&1
  31. ::taskkill /f /im firefox.exe > nul 2>&1
  32. ::taskkill /f /im chrome.exe > nul 2>&1
  33. ::taskkill /f /im iexplore.exe > nul 2>&1
  34. ::taskkill /f /im opera.exe > nul 2>&1
  35. echo Sleeping automatically in five seconds!
  36. choice /c:yn /n /t 5 /d y /m "Do you really want to sleep? y/n: "
  37. set slstatus=%ERRORLEVEL%
  38. if "%slstatus%"=="2" (
  39. echo Sleep cancelled.
  40. goto end
  41. ) ELSE (
  42. echo ~SLEEP~ | rundll32.exe powrprof.dll,SetSuspendState 0,1,0
  43. )
  44. goto end
  45.  
  46. :end
  47. echo TASK DONE
  48. ping 127.0.0.1 -n 2 | find "Reply" > nul
  49. exit /b

Report this snippet  

You need to login to post a comment.