RT @SjoerdvanHoorn: Portugal schaft de BTW op essentieel voedsel af.
Het kan dus wel, maar in Portugal hebben ze dan ook niet de Nederlan… 10 minutes ago
RT @kovanhuissteden: 🧵: Kalk strooien in verzuurd bos.
Het is volgens BBBoeren het beste medicijn voor bossen die verzuren door de neersla… 53 minutes ago
RT @kovanhuissteden: De veroorzakers van de schade - de grote stikstofuitstoters, de vlees, zuivel -en veevoergiganten zeker niet.
Nee da… 53 minutes ago
/g Shutdown and restart the computer. After the system is
rebooted, restart any registered applications.
I never noticed it until Windows 10 which began actively use it when applying system updates: then suddenly many of the previously running applications would reopen during startup.
Windows 8.x: “Shutdown” became “Full shutdown” in the /s and /g switches, added /hybrid and /o switches:
/r Full shutdown and restart the computer.
/g Full shutdown and restart the computer. After the system is
rebooted, restart any registered applications.
...
/hybrid Performs a shutdown of the computer and prepares it for fast startup.
Must be used with /s option.
...
/o Go to the advanced boot options menu and restart the computer.
Must be used with /r option.
Windows 10: amended help for /g switch with “Automatic Restart Sign-On” information and /a switch with /fw information, and added /sg and /fw switches:
/sg Shutdown the computer. On the next boot, if Automatic Restart Sign-On
is enabled, automatically sign in and lock last interactive user.
After sign in, restart any registered applications.
...
/g Full shutdown and restart the computer. After the system is rebooted,
if Automatic Restart Sign-On is enabled, automatically sign in and
lock last interactive user.
After sign in, restart any registered applications.
/a Abort a system shutdown.
This can only be used during the time-out period.
Combine with /fw to clear any pending boots to firmware.
...
/fw Combine with a shutdown option to cause the next boot to go to the
firmware user interface.
It appears that Windows Vista already understood the /s and g combination to perform a full shutdown, but remember the applications that started.
Preparing your applications for reopen after Windows shutdown or restart
The /g option will restart applications that are registered for restart with the RegisterApplicationRestart API.
The Windows Restart Manager (introduced in Windows Vista) supports gracefully shutting down and restarting applications that registered for restart with the RegisterApplicationRestart API.
This functionality is used by Windows Update – thanks to the Restart Manager, when I come yawning to my desktop PC in the morning, even following a system restart, I have my Outlook, browser windows, OneNote, Visual Studio, and Messenger all lined up as they were when I went to bed.
Suppose you want to initiate one of these “automagically restart everything after restart” restarts. As of a few weeks ago, I had it in my head that you have to write a small app that uses the Restart Manager APIs (e.g. RmStartSession and RmShutdown) to do this.
And then it hit me that the shutdown command must have support for doing this. And indeed, it has:
Vista (and thus Server 2008) contains a new Restart Manager, which enables this feature and is used automatically by Windows Installer 4.
To enable your application to restore its sessions, you simply listen for WM_QUERYENDSESSION with an lParam of ENDSESSION_CLOSEAPP(save your state there) and register your application for restart using RegisterApplicationRestart (which is part of the automatic recovery functions, see the MSDN for the P/invoke signatures). If you have a console application, you can also use a CTRL_C_EVENT handler (or the Console.CancelKeyPress event) to save your state, but in this case, you have to call RegisterApplicationRestartbefore you get that notification. See the MDSN for more comprehensive guidelines.
And that’s it, your application is ready for a clean Windows Update experience.
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if (m.Msg == WM_QUERYENDSESSION) //0x0011
{
if ((m.LParam.ToInt32() & ENDSESSION_CLOSEAPP) == ENDSESSION_CLOSEAPP) //0x1
{
// some installation will shut us down next, so do some cleanup (prepare for it)
File.WriteAllText(Environment.CurrentDirectory + @"\rm.txt", "for demo purposes");
//MessageBox.Show("intercepted", “RM request”);
}
}
}
I wondered how long ago that was introduced…
I still have Windows XP and Windows 7 VM’s for experiments like this. Windows XP shutdown.exe didn’t have it, but Windows 7 shutdown.exe had.
/t xxx Set the time-out period before shutdown to xxx seconds.
The valid range is 0-315360000 (10 years), with a default of 30.
If the timeout period is greater than 0, the /f parameter is
implied.
...
/f Force running applications to close without forewarning users.
The /f parameter is implied when a value greater than 0 is
specified for the /t parameter.
/t 0 does not imply /f
/t 1 implies /f, but the time-out is so short that nobody can cancel, so it is sort of immediate
Looking at the Windows XP help for shutdown.exe, I realised two things:
I never looked at the switches after Windows XP, so I totally missed the /f, /g and /sg ones
People still use the minus sign (-) to prefix shutdown.exe switches instead of the slash (/) as that was the preferred prefix until Windows XP.
Usage: shutdown [-i | -l | -s | -r | -a] [-f] [-m \\computername] [-t xx] [-c "comment"] [-d up:xx:yy]
No args Display this message (same as -?)
-i Display GUI interface, must be the first option
-l Log off (cannot be used with -m option)
-s Shutdown the computer
-r Shutdown and restart the computer
-a Abort a system shutdown
-m \\computername Remote computer to shutdown/restart/abort
-t xx Set timeout for shutdown to xx seconds
-c "comment" Shutdown comment (maximum of 127 characters)
-f Forces running applications to close without warning
-d [u][p]:xx:yy The reason code for the shutdown
u is the user code
p is a planned shutdown code
xx is the major reason code (positive integer less than 256)
yy is the minor reason code (positive integer less than 65536)
–jeroen
I remembered that, when I was in hospital, @JenMsft a while back mentioning that you can manually shutdown and save apps for reopen after booting.
Gist with Windows 7, 8.1 and 10 help for shutdown.exe.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Leave a Reply