I'm afraid there will be only one:
A shortcut tied with any keys combination like CTRL+SHIFT+S.
It allow you to run your script or any program you like,
then call "shutdown /s /f /t 0" to close all operations.
If you don't need to use any "start" command,
the sequential execution will ensure that all instances will run properly before shutting down.
_________ copy ___________________________________________ a) __
Chain command since 2000, and still good today:
(before it was the "|" pipe)
If you want the second command to execute only if the first exited successfully:
(that ensure you'll shutdown only if preceding instances was successful)
But if you need to pass variable between one command and the others...
>>Delayed Expansion feature only available
in batch files BAT, CMD:<<
Ex:
setlocal EnableDelayedExpansion && set MyVar=MyVal && echo !MyVar! && endlocal
(NOTE: The feature requires you to use ! marks in place of the % symbols.)
________________________ end copy ______________________
For what I know Windows has no way to recognized itself any instance to run BEFORE closing operations, unless using Group Policy.
But out of Windows you can try this with AutoHotKey
_______ copy____________________________________ b) _____
I made a basic batch file that will create a "test file" on the desktop. Just run the AHK file and leave it running. When the script detects a shutdown, it'll run the batch file.
This script is tested and working.
Make sure you set the path to your text file at the top of the script.
AutoHotkey Script:
;==============================
;Set the path to your batch file.
path := "C:\batch.bat"
;==============================
; Run script as admin. This will allow your batch file to be ran with admin priv.
if not A_IsAdmin
{
Run *RunAs "%A_ScriptFullPath%" ; Requires v1.0.92.01+
ExitApp
}
; Only allow one instance of the script to run.
#SingleInstance, Force
; If you don't want an icon to show in the tray,
; remove the semicolon from the line below.
;#NoTrayIcon
; When script detects WM_QUERYENDSESSION (a shutdown), run OnShutDown function.
OnMessage(0x11, "OnShutDown")
return
OnShutDown(){
; Run the batch file.
Run, % path
ExitApp
}
Batch file I used for testing:
echo Write file before shutdown > %USERPROFILE%\Desktop\ShutdownTest.txt
If you wanted to, you could always execute your batch file commands directly through AHK.
_________________________end copy ___________________
I stumbled upon this question myself time ago, it was easy to recover my findings.
I Hope you'll find that useful.
( for myself I use BAT and ShortCuts )
Alain
References:
a)
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ntcmds_shelloverview.mspx?mfr=true
b)
https://superuser.com/questions/1202064/how-do-i-run-a-batch-script-at-shutdown-in-windows-10-home-edition