The value of this article is not in the solution itself, but in a reminder how to quickly solve simple problems.
But if you need a simple solution, please:
Save these lines in CMD and after starting in 20 minutes (1200 seconds) the computer will go into sleep mode. In total, the program took 73 bytes :
ping 127.0.0.1 -n 1201 > nul
rundll32 powrprof.dll,SetSuspendState 0,1,0
But if you just need to turn it off , then everything will be even shorter, namely 47 bytes . Just the second line will look like:
shutdown -s -t 00
I use this before going to bed, including my favorite online radio "for sleep to come" also from the command line, which will be discussed under the cut.
Who is still curious, please, under the cat. Links to ready-made scripts at the end of the article.
For the most part, everything new is well forgotten old.
First, let's look at what these lines do:
We ping an IP address that is always available (unless your firewall is configured "fancy"). The default interval is 1000 ms = 1 second. The -n switch specifies the number of repetitions 20 minutes x 60 seconds = 1200 + 1 (since the first ping is returned in less than 1 ms). And the > nul construct tells the interpreter that the standard output will be sent to nul in order to get rid of unnecessary output to the screen.
ping 127.0.0.1 -n 1201 > nul
The rundll32.exe program is called to execute a DLL routine. In this case, SetSuspendState with the parameters we need. Detailed description on MSDN .
rundll32 powrprof.dll,SetSuspendState 0,1,0
It should be noted that if you have enabled hybrid sleep mode ( Hibernate ), then it will enter this mode. You can disable it by running the following as administrator:
powercfg -hibernate off
There are a few more uses under the spoiler for example ...
Winamp .
(WIN + L).
(Hibernate).
.
( ).
.
.
.
.
, WinAPI .
start winamp http://cast.loungefm.com.ua:8000/acoustic128
(WIN + L).
rundll32.exe User32.dll,LockWorkStation
(Hibernate).
rundll32.exe PowrProf.dll,SetSuspendState
.
shutdown.exe -r -t 00
( ).
rundll32 user32.dll,SwapMouseButton
.
rundll32 shell32.dll,Control_RunDLL main.cpl,@0,1
.
rundll32 user,SetCursorPos
.
rundll32 user,CascadeChildWindows
.
rundll32 user,TileChildWindows
, WinAPI .
There is a well-known expression that many people like:
Laziness is the engine of progress.
A bit of history:
Back in 2003, a simple program was quickly written to turn off the PC on a timer. I wrote it myself, because at that time I did not have any familiar programmers and access to the Internet. I am sure that many of the same "home programmers" who bought or cut into MSDN discs studied Windows programming all night long. On the occasion of writing the article, I opened it in an old archive on my parent's PC. She looked simple, but fulfilled her task. As it turned out, even now several of my friends use it.
I donβt remember what it was written on (VC, VB, Delphi or Assembler). Its size was also not large, but still 16 166 against 47 bytes do not go into any comparison.
And when a couple of days ago I needed the same functionality, I started looking for similar software. Imagine my disappointment when I found a bunch of programs on average from 1.1 MB to huge monsters of 15.2 MB in size. Naturally, my conscience did not allow me to launch this heresy even in the sandbox. Realizing that I need a execution delay of 20 minutes and calling only one procedure, I remembered rundll32.exe , got into the Internet and was not mistaken. As a result, the solution was found in 1 minute.
Morality:
We often do not need third-party software to solve simple tasks. It is enough just to go to a search engine and find a simple solution to the problem, which in 98.785% is already in the public domain. Of course, we need to mention another way, for real IT specialists, turn on the imagination, go to the MSDN manuals and use the ready-made OS functionality. You must admit that it is pleasant to use simple and elegant solutions, but it is doubly more pleasant when you come to their decision with your own mind.
As promised earlier links:
Scripts for shutdown timers, start the radio and switch to sleep mode - radio_sleep_scripts.zip
Suddenly my old craft will be interesting - ExitXP.exe
I hope you enjoyed my first post. I would be glad to have comments and suggestions regarding the article. I would like to see your interesting solutions to similar problems in the comments. Thank you for your time and read to the end.