Tuesday, October 31, 2023

2023-10-30 - Writing A Script/Batch File for instant sleep mode on Windows 11

 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?

I am trying to make a desktop icon which when clicked puts the computer to sleep. I tried searching a lot but didn't find anything. Maybe a batch file would work by changing the icon of a shortcut. But I can't find a command that puts windows 10 to sleep. The code I found hibernates it. 

(@echo off

echo %time% timeout /T 1 && rundll32.exe powrprof.dll,SetSuspendState 0,1,0
echo %time%
)


I need something like this on the desktop

A way to pin this to the taskbar would also be helpful!

You'll need a third-party tool to put your computer to sleep using command-line.

Try one of the many options discussed here:

Put Windows Into Sleep or Hibernate Mode Using Command-line

How can I put the computer to sleep from Command Prompt/Run menu?

You can use the PsShutdown tool [download] from Microsoft Sysinternals.

The command-line to put your computer to sleep is below:
"

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

Tuesday, October 24, 2023

2023-10-23 - NTFS Folder Mounting...In Windows 10

 This is a problem I have had for several years now, and had no answer for it--until now. Many games these days take up 80 GB or even 140 GB and there's no apparent sign that this is going to stop climbing anytime soon. A lot of the time the C drive isn't a terribly large drive. 

My C drive on my desktop is a 256 GB SSD. Nine years ago when I was only just thinking about how to spend some money I had, and I had always wanted to break into the SSD world, I decided I was going to switch the C drives in my laptop and desktop to SSD's. But I also had this idea that to stretch my money further, I wouldn't buy anything of any extravagance that I didn't have to. 

I also bought a lightweight, compactly broken down tripod for my camera for about $70 around this same time, and there was a slightly taller one when fully extended for ten dollars more. The salesman at the Photography store debated with me why I wouldn't just get the bigger one, it's only ten dollars. And I was not going to just arbitrarily spent money I didn't have to spend. They guy was like, but it carries a half pound more than the smaller one and this and that. I said, well, I only need it to carry the camera I have. So this doesn't matter to me. He just didn't seem to get it. 

So to save some more money, I decided that since there was only room for one drive in my laptop that I would buy a bigger drive for it and keep to the maximum size that I thought I would ever actually need for my desktop. Since it had many TB of hard drives plugged into it, there was no reason to spend tons of money on another 500 GB SSD for it, so I did one 500 GB SSD for the laptop and one 256 GB drive for the desktop. I have however come to regret this a few times. But I now have the capacity to switch to an M.2 NVME so it doesn't matter that much anymore. 

So when I decided I wanted to play World of Warships a few years ago, I tried to install it and it simply wouldn't run the game. The Wargaming application opened but the actual game itself would never open. I had installed it on an external drive because I simply didn't have enough space on my C drive for it. So I have become a big fan of World of Warships but have never once played it. I have been watching The Mighty Jingles, Flambass, and Flamu for years now with regularity, but never even opened the game. 

I can only assume that installing the game on any other drive but the C drive is the reason it never worked. However, now I know what would have likely solved it. In Windows, there is a feature for NTFS Folder Mounting. 

So imagine you have a new drive, and for gaming in particular, and other reasons, when you mount the drive in Disk Manager, you right-click on the unpartitioned space disk > select New Simple Volume, next > enter size, next > and instead of selecting drive letter, there's a bullet selection for assigning a letter, another for simply leaving the drive without an assigned drive letter, and there's also an option for "Mount in the following empty  NTFS folder. Select this option.  Click Browse > click the plus under the C directory, and then you can expand Users > then (user name) > Desktop > and click New Folder > name this folder whatever you would like to name it for the purpose it will be fulfilling > click OK. 

This will trick the computer into allowing you to save anything meant for the C drive on another drive, such as programs and applications including your excessively large games. 

This has been Truncat3d 00000000111100010100110______________end of line

2025-07-10 - BYU Wi‑Fi captive portal troubleshooting

  BYU Wi‑Fi Captive Portal Troubleshooting What happened I had used BYU Wi‑Fi just fine before, but at some point, the captive portal star...