The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Email Subscription

    Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 716 other subscribers

Windows: shutdown or reboot while preserving most of the running apps has been possible since…

Posted by jpluimers on 2022/05/26

Vista!

Shutting down or rebooting Windows allowing existing applications to reopen

Windows Vista introduced the /g switch in shutdown.exe and was unchanged in Windows 7:

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

Note that a nice overview of the various shutdown.exe help texts are at [Wayback] MS-DOS and Windows command line shutdown command. I put the Windows 7, 8.1 and 10 help in the below gist revisions.

The major differences:

  • 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

There is the [Wayback] RegisterApplicationRestart function (winbase.h) – Win32 apps | Microsoft Docs that allows you to register your application to restart when Windows restarts. You can listen to events to save your application state right before Windows restarts.

Some links:

Jen Gentleman on shutdown.exe switches

Some posts by Jen Gentleman and replies to them via [Archive.is] @JenMsft shutdown – Twitter Search:

All of the above because of [Wayback] Thread by @jpluimers on Thread Reader App – Thread Reader App:

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.

She did, multiple times: [Archive.is] twitter.com/search?q=from%…

It’s the /g switch of shutdown.exe

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.

So when was it introduced?

… drumroll …

superuser.com/questions/1132091…

Windows Vista!

I’ve been living under a stone for a long time (:

The superuser post also mentions docs.microsoft.com/en-gb/windows/…RegisterApplicationRestart [Wayback]

I sense a blog post coming up about it.

Thanks @JenMsft for teaching an old fart something new!

/t 1 versus /t 0 and Windows XP shutdown.exe help

When writing this, I wondered why some people consistently use /t 1 (timeout ) and others /t 0, and even asked for explanation [Archive.is] Jeroen Wiert Pluimers on Twitter: “why /t 1 instead of /t 0 ?… “ (but no answer).

The reason is simple:

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

  1. I never looked at the switches after Windows XP, so I totally missed the /f, /g and /sg ones
  2. 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


Gist with Windows 7, 8.1 and 10 help for shutdown.exe.

https://gist.github.com/jpluimers/a3d7584b88ab5f33c9de51c161fdfdc3

Leave a Comment