Windows 8 and logoff/restart/shutdown shortcuts ...


Welcome, Guest. Please login or register.
Username:   Password:

Hosted in the Cloud RSS

Recent Topics

Gallery Latest


485 Views
0 comment(s)

466 Views
0 comment(s)


799 Views
0 comment(s)

642 Views
0 comment(s)


515 Views
0 comment(s)

527 Views
1 comment(s)

Search The Gallery

User Info

Welcome, Guest. Please login or register.
June 28, 2017, 01:25:33 AM

Login with username, password and session length

Forum
Web
Gallery
Search:         Keywords:

   

DatahopaForumComputer RelatedPC Software Windows 8 and logoff/restart/shutdown shortcuts



Pages: [1]

Windows 8 and logoff/restart/shutdown shortcuts

Viewing: 0 Members and 1 Guest       Total Views: 1935

Offline DaveMorton Topic starter
United States WWW Global Moderator
Posts: 2505
Rank: Certified
Comfort the Disturbed! Disturb the Comfortable!

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! Shocked And to top it all off, the shutdown process FORCED all of my apps to close, so that unsaved work I mentioned? Lost. Sad

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":

Code:
@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.
echo.

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%?
echo.

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

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

:action_cancelled
echo Action cancelled.
echo.
goto end

:unrecognized_command
echo You entered an unrecognized command. This script will now terminate.
:end
echo.
pause

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. Smiley

Anyway, I thought I would share.


shutdown_shortcut.jpg
Windows 8 and logoff/restart/shutdown shortcuts
* shutdown_shortcut.jpg (33.07 KB, 386x534 - viewed 283 times.)
Posted March 16, 2013, 01:07:25 AM Logged
Safe, Reliable Insanity, Since 1961!
Chat With Morti!

CAPTCHA4us

Offline sybershot
United States WWW Posts: 1370
Rank: Certified

I will be using this, Thanks Dave  thumbsup thumbsup
Posted March 16, 2013, 01:19:58 AM Logged

Offline DaveMorton Topic starter
United States WWW Global Moderator
Posts: 2505
Rank: Certified
Comfort the Disturbed! Disturb the Comfortable!

Real quick-like, here's another screenie:


logoff_verify.jpg
Windows 8 and logoff/restart/shutdown shortcuts
* logoff_verify.jpg (18.85 KB, 677x343 - viewed 258 times.)
Posted March 16, 2013, 01:23:36 AM Logged
Safe, Reliable Insanity, Since 1961!
Chat With Morti!

CAPTCHA4us

Offline Data
United Kingdom Administrator
Posts: 4624
Rank: Certified

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
Posted March 16, 2013, 02:34:10 AM Logged

Offline DaveMorton Topic starter
United States WWW Global Moderator
Posts: 2505
Rank: Certified
Comfort the Disturbed! Disturb the Comfortable!

Only too happy to help, mate. Smiley
Posted March 16, 2013, 14:18:08 PM Logged
Safe, Reliable Insanity, Since 1961!
Chat With Morti!

CAPTCHA4us
Pages: [1]
Jump to:  

Site Activity
Most Online Today: 160
136 Guests, 1 User
Urania