So I like using hibernation primarily for all my laptop needs because it saves the most power without totally shutting down and also recovering all of my work, saved or not. The problem with this is that sometimes I just want to use the bathroom for a few minutes and either want temporary security or some power savings but still get the benefit of recovering within a second or so, which even if hibernation is fast, it still takes like fifteen or twenty seconds. Sometimes I want to attend to something and I don't have much time or there's a fleeting idea I want to explore before it's gone. Maybe I'm keeping notes during a lecture. Occasionally speed is irreplaceable and loss likely.
I had this idea, not having written any scripts successfully in my life but having been highly interested, I decided I wanted something that I could put my laptop into sleep mode instantly with, without a bunch of button clicks, without having to navigate through tedium to reach it. I don't want to just use Windows + L because that just logs you out and only after a few minutes does it go to sleep if you have that feature set to do so.
My interest in scripts came from back in 2016, I read some tech article somewhere that talked about the crazy stuff you could do with scripts, and it told this story about this one dude in an office that had moved on to a new job and his former co-workers had the job of cleaning up his computer and desk for a new hire. So they were going through his computer and were stunned at the discoveries they made. Apparently there wasn't anything about his job that he didn't find some way to automate using scripts.
Basically he'd come to work in the morning, and he'd turn on his computer, log in and click on the first script which in turn then activated a number of other scripts to run, and one of the first ones to start was to tell the coffee machine in the break room to start brewing. You se, the coffee machine in this break room had a LAN port because it was a smart coffee maker, an IoT device (internet of things). And this coffee machine ran Linux. So he had a script that communicated with that coffee machine and within the time that it took this guy to start his computer and get the scripts running to the time that he got to the break room, a cup of coffee will have been poured.
When he got back to his desk, the scripts will have already automatically filtered through all of his work emails to check for any key words in those emails so that whatever the request in those emails was, he had keywords and phrases programmed into the script so they would recognize them and automatically reply back with the necessary information. These are just a few examples of the things this guy had running on scripts. It seemed to me when I first read this article, the guy basically didn't have to do anything because he had scripts doing it all. I also thought I probably won't take it to that level, but it'd sure be cool to learn how to do that because there are plenty of things that I would like to do with a simple double-click or keyboard stroke from the desktop.
https://www.stuff.co.nz/technology/digital-living/99164024/a-programmer-wrote-scripts-to-secretly-automate-his-job
These articles also had a GitHub link for some of the scripts this guy wrote: Click Here
Anyway, I found instructions online for how to put my laptop to sleep at the click of an icon. They said to right-click on the desktop > go New > Create Shortcut > in the shortcut window as the location of the item, type "powershell.exe -Command "Add-Type -AssemblyName System.Windows.Forms; [System.Windows.Forms.Application]::SetSuspendState('Suspend', $false, $false)".
This uses the suspend state method to put your computer to sleep. Click Next > name the shortcut something like Sleep Computer > click Finish.
So now I had a shortcut icon on my desktop for putting my laptop to sleep. I double-clicked it and it did nothing. I don't know why this didn't work, I did some research and it pointed to the possibility of administrator permissions getting in the way. It suggested to right-click on it and go Run As Administrator. I did that and it still did nothing. Every time I clicked on it, the CMD or PowerShell window would appear for about a half second and then nothing would happen.
The next attempt from my brief online research was to open a text document > enter "@echo offrundll32.exe powrprof.dll,SetSuspendState 0,1,0" > save the file and change the file extension to a ".bat" > and windows will ask for confirmation when doing this because randomly changing any file extension can cause a file to become unstable. But this is a common thing and a .bat file can be created from a text document from something like notepad. Then my instructions told me to right-click on this .bat file > go Create Shortcut > put this on your desktop > double-click on it, and it should put my computer to sleep.
This time when I clicked on it, a command prompt window even more briefly appeared and still did nothing. However, with more research I found something I had forgotten about shortcut icons.
Shortcut Icon Keyboard Command
In my further research I sort of accidentally re-discovered that when you create a shortcut icon, and then right-click on it > go properties > select the shortcut tab, you can then go down to the Start In section of the window and in the Shortcut Key field type the keyboard shortcut you want to use in order to activate whatever that shortcut leads to. So you don't type what keyboard buttons you want to use, instead you decide what keyboard shortcut you want to use, which can be tricky because you don't want to override another keyboard shortcut, especially if you commonly use it, but if not then it doesn't matter, jsut keep in mind when maybe you suddenly need it, it's used for something else other than it's default use. And when you create the kayboard shortcut, you hold the keys in the order that they'll be typed. So for example, "Command + Alt + S" which is what my research suggested for my sleep mode command, you'll simply hold the command key, and then also the alt key and then also the S key and let go. The field will indicate the key combination recorded and you press Apply >OK, and you're finished.
This didn't really matter all that much since I hadn't actually gotten this command to put my laptop to sleep. I asked for some hel from Jack, one of my classmates who's been coding for years and is well versed and is one of the smartest in the class. He looked at the code and wondered if perhaps it would activate when clicked, but the mouse moves subtly after clicking so it never actually suspends. So he looked up the code for activating the command for a few seconds after double-clicking on the .bat icon for the command. This also didn't work. He couldn't help me for very long though because he was busy with an assignment.
Then
Doug came at the end of class, after everybody was gone, as usual, to try and help me figure this out. He looked at the code and discovered that I had made a mistake when typing the code. I had mistaken the "runll32.exe" command for "run1132.exe". They look exactly the same except that in the first one, there are two lower-case L's and I typed two number 1's (one's) instead.
This still didn't fix anything. Then Doug did some research. He found this: A file that puts the computer to sleep when clicked? - Microsoft Community
"
A file that puts the computer to sleep when clicked?
Using PsShutdown
PsShutdown is part of the PsTools suite from Microsoft Windows SysInternals which every sysadmin would have in their toolkit. Here is the command-line to place the system into sleep mode.psshutdown -d
When you use this tool for the first time, you’ll see a EULA screen which you need to accept to proceed."
So we installed the PsShutdown tool. I didn't really understand this next part. Shouldn't the tool then go in a file directory where a bunch of shutdown tools are? According to Doug, no. It just needs to be dropped in a common file path. So he went to This PC > C drive > Windows > System 32, grabbed it and dropped it there.
![]() |
Then we edited my previous .bat file to simply say "psshutdown -d -t 0", saved it, I put it in my Downloads folder just to put it somewhere out of the way.
There was no reboot. We tested it. Upon clicking the file the command prompt appeared very briefly and the laptop went to sleep. I created a shortcut now this time so that I could then click on the shortcut >hold Alt and press Enter > go shortcut tab > enter the Control + Alt + S key combination again > pressed Apply and Ok and then tried the shortcut and it worked. Then I tried the keyboard combination while the desktop was selected and it worked.
I would like to say that this is it. And it should be. But the next day it stopped working. I moved the shortcut I left next to the main .bat file in the Downloads folder back to the desktop, it still didn't work. What am I doing wrong?
I don't know if what I did fixed anything or if it did, what it fixed. So I deleted the shortcut and re-copied the .bat file, pasted it to the desktop and re-configured the keyboard combination. When clicking the shortcut, it works. And then when I did the keyboard combination while the desktop is selected, it did nothing...for about 3-5 seconds and then it went to sleep. What's the deal? I don't know. But it's working again for now.
This has been Truncat3d 00000000111100010100110______________end of line