Secure Sockets Layer


Hello Guest
Did you know this forum has been running since 2010?


Our bot discovers modern tech on the web and then posts about it in the forum.

Recent Topics

Stop Burning Stuff


Can You Help?

Help keep our site running
Advert free.

Web Utilities

Windows 8 and logoff/restart/shutdown shortcuts

Started by DaveMorton, March 16, 2013, 01:07:25 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic. Total views: 3,643


As those of us who have Windows 8 are well aware, Windows 8 treats logging off, rebooting and shutting down a but differently than it's predecessors, and some of us, myself included and especially, have found it to be a pain to get to where we can tell the OS what to do in these respects. I'm sure that you all are aware of various 3rd party "solutions" that address this in one form or another, and in all honesty, I use a couple of those 3rd party apps myself, though for other reasons. I've also seen blogs and articles on how to create desktop shortcuts to accomplish the actions I'm referring to, and I've created these shortcuts, and up until today, have used them, but no more.

You see, the primary disadvantage to using these custom created Windows shortcuts for logging off, restarting the computer and shutting down is that there's no confirmation, no warning, and no chance to recover if you make a mistake. I found out the full impact of this earlier today, when I had a couple of apps open, some with unsaved work, and accidentally activated the "shutdown" shortcut when I intended to open SpeedFan (desktop navigation with the keyboard while the shortcuts are hidden behind windows is a dangerous thing, lol). Suddenly, without any notice at all, my computer is shutting down, and there's not a blessed, bloody thing I can do about it! I wanted to scream! :o And to top it all off, the shutdown process FORCED all of my apps to close, so that unsaved work I mentioned? Lost. :(

When I finally got over my rage attack, I sat down, pulled open "Batch File Programming for Dummies", and went to work.

The interesting thing about all of the 3 shortcuts for "leaving Windows" is that they all call the same file: shortcut.exe - The only difference between the shortcuts are the command line switches they send to the program, so that got me to thinking. I already knew that the MSDOS file choice.exe (or more accurately, it's Win32 equivalent) still exists, mainly for legacy reasons, so that gave me an idea about how to "fix" the problem of sudden accidental shutdown. What follows is that "fix":

@echo off

REM verify_intentions.bat
REM Verifies that you do, indeed, want to shut down, reboot, or log off
REM Accepts one command line argument, of either "logoff", "restart" or "shutdown" and acts accordingly. Any other value
REM passed (including an empty value) is treated as an "unrecognized command", and ignored.

if "%1"=="" goto unrecognised_command
echo Please verify your intentions.

set switches=
if "%1"=="shutdown" set switches=/s /t 0
if "%1"=="restart" set switches=/r /t 0
if "%1"=="logoff" set switches=/l
if "%switches%"=="" goto unrecognized_command

if "%1"=="shutdown" set label=turn your computer off
if "%1"=="restart" set label=reboot the system
if "%1"=="logoff" set label=log off

echo Are you sure you want to %label%?

choice /C YN /n
if errorlevel 2 goto action_cancelled
if errorlevel 1 goto verified
goto end

echo Action verified. Please save your work, and make sure that you're ready to %label%.
C:\Windows\System32\shutdown.exe %switches%
goto end

echo Action cancelled.
goto end

echo You entered an unrecognized command. This script will now terminate.

To use this simple batch file, simply paste the above code into Notepad and save it to a convenient location as {whatever}.bat. Then create a shortcut on your desktop (or wherever you like) that points to the newly created batch file, with the argument "logoff", "restart" or "shutdown", depending on what you want the shortcut to do. For example, look at the screenshot below for my shortcut to shut down.

When you now click on the shortcut, the batch file verifies first that it was given one of the three "authorized" commands. If not, it complains about it and exits. If the command matches, it then asks you if you're sure that's what you want to do. If it wasn't, you simply hit N for no, and the action is canceled and the batch file terminates. Otherwise, the script looks at the command, sets the command line switches for shutdown.exe accordingly, and executes the program. The batch file DOES, however, give you the opportunity to save any work first, just as a precaution, to prevent mishaps. :)

Anyway, I thought I would share.
Safe, Reliable Insanity, Since 1961!



Real quick-like, here's another screenie:
Safe, Reliable Insanity, Since 1961!


Nice work Dave, sure to come in useful.

Incidentally this topic helped me track down a bug in the site where some content was going off page, finally I've found the problem, had to make some changes to the CSS, would need to force a reload to see the changes.

Thanks  :thumbsup:


Safe, Reliable Insanity, Since 1961!