Back to Basics: Windows Shutdown Autostart explained - gHacks Tech News

ADVERTISEMENT

Back to Basics: Windows Shutdown Autostart explained

Windows supports autostart functionality; the autostart on startup feature is the better known variant but there is also an option to autostart on shutdown.

Some programs add entries to the autostart list when they are installed. Programs like antivirus and security software may add entries so that they are launched as early as possible on the Windows PC.

Windows administrators may configure devices running Windows to run certain programs or scripts during shutdown as well. Examples include running a script to clear temporary folders or the browsing history on the device, backing up certain files, delaying the shutdown of the system, or adding entries to log files.

The caveats

The autostart of programs or scripts during shutdown of the system has two caveats that need to be mentioned. First, that the functionality is only found in professional or Enterprise editions of Windows and not in Home versions, and second, that the scripts or programs are run on every shutdown or restart.

The autostart entries are run each time, e.g. after installing updates that require a restart or installing a program that requires a restart to finalize the installation.

The shutdown

windows tutorial shutdown autostart

The shutdown of the system begins with the termination of running (user) processes and signing out of the user. System processes are shut down after that first phase, and the device is turned off or restarted in the end. Windows supports running tasks in both of the shutdown phases, and both may be configured in the Group Policy Editor.

  • User Configuration > Windows Settings > Scripts (Logon/Logoff) > Logoff
  • Computer Configuration > Windows Settings > Scripts (Startup/Shutdown) > Shutdown

The first policy runs scripts during user log off on the system, the second after the user has been logged out of the system.

The script's purpose determines where you need to add it for execution on shutdown. Scripts that you configure in the user configuration run with the rights of the user. The scripts are started after the termination of running processes including those that run in the system tray or in the background.

Windows displays a blank screen usually when configured scripts are run but it is possible to run scripts with graphical user interfaces that the user may interact with. Scripts are terminated automatically unless configured to do otherwise, e.g. by using the wait command.

display instructions in logoff scripts as they run

You may also configure a policy to display a window when scripts run so that you know what is happening. Enable the policy "Display instructions in logoff scripts as they run" under User Configuration > Administrative Templates > System > Scripts to do so.

A similar option is available for scripts that run in the second phase of shutdown. You find it under Computer Configuration > Administrative Templates > System > Scripts; it has the same name as the User Configuration policy: Display instructions in shutdown scripts as they run.

Windows gives the combined scripts 10 minutes (600 seconds) of execution time by default. You can change the interval by configuring "Specify maximum wait time for Group Policy scripts" in the same Computer Configuration policy folder. You may select a range between 0 and 32000 seconds; 0 means that scripts run for as long as they need and that Windows won't interfere. Note that the policy affects startup and shutdown scripts.

Shutdown scripts, those run in the second phase of the shutdown process run when no user is logged in anymore. These scripts run with system rights and not user rights. Administrators need to be aware that referenced user folders in scripts use the folders of the system user.

The shutdown and logoff properties policy windows look identical. Both feature a tab that separates scripts from PowerShell scripts, options to add, edit, remove, and sort scripts, and a button to show files.

shutdown properties

A click on show files opens a script directory on the local system:

  • For Logoff scripts: C:\WINDOWS\System32\GroupPolicy\User\Scripts\Logoff
  • For Shutdown scripts: C:\WINDOWS\System32\GroupPolicy\Machine\Scripts\Shutdown

You may place the scripts that you want executed in those folders; it is no requirement though and you can pick any folder on the system that is accessible during shutdown for storage.  It may nevertheless be a good idea to place scripts in these folders for organizational purposes.

Summary
Back to Basics: Windows Shutdown Autostart explained
Article Name
Back to Basics: Windows Shutdown Autostart explained
Description
Windows supports autostart functionality; the autostart on startup feature is the better known variant but there is also an option to autostart on shutdown.
Author
Publisher
Ghacks Technology News
Logo
Advertisement

Previous Post: «
Next Post: »

Comments

  1. Niko said on August 19, 2019 at 9:23 am
    Reply

    Nice article, thank you!

  2. Benjamin said on August 19, 2019 at 10:37 am
    Reply

    Back to basics indeed… why not?

  3. Henk said on August 19, 2019 at 12:17 pm
    Reply

    OK, this nice overview here offers me an excuse to ask a (somewhat) related question.

    For years now, I have been trying to somehow get a shutdown script that, in a situation where Dropbox is still busy syncing files, will delay the actual shutdown until Dropbox has finished doing its sync job. I’d like to have such a script because of my own forgetfulness! For sometimes I just shutdown in a hurry, without noticing that Dropbox hasn’t finished syncing yet. And when this syncing is a aborted by a shutdown, it may cause all kinds of problems: such as finding out too late that a newly created file is still missing on another device, or getting different “duplicates” of the same supposedly synced file.

    As far as I know (of course I did search for it) Dropbox itself offers no ready solution for this problem, so some kind of shutdown script would be the ideal solution here. For example, theoretically I can imagine a shutdown script that would, in a continuous loop, keep testing for ongoing internet traffic and that would escape from this loop only when there has been no internet traffic for more than a few seconds. Unfortunately I don’t think I would be capable of writing such a script myself.

    Is there anyone here who could point me in the right direction? Or who, perhaps, has an entirely different solution for the same problem, one that I didn’t think of?

    Thanks!

    1. Martin Brinkmann said on August 19, 2019 at 12:59 pm
      Reply

      I don’t think that there is an easy solution for that. Dropbox does not seem to support it which means that you need to turn to third-party solutions or your own solution. I found this guide, but cannot say if it still works as I don’t use Dropbox: https://www.ampercent.com/shutdown-standby-sleep-computer-dropbox-sync/8006/

    2. HaveALook@This said on August 19, 2019 at 2:27 pm
      Reply
    3. Cigologic said on August 20, 2019 at 1:41 am
      Reply

      > Henk: “a shutdown script that would, in a continuous loop, keep testing for ongoing internet traffic and that would escape from this loop only when there has been no internet traffic for more than a few seconds.”

      The lightweight software ‘Don’t Sleep’ has an option that:
      • blocks system shutdown/ hibernation/ sleep, when there is active network traffic;
      * & triggers system shutdown/ hibernate/ sleep, only when network data transfer falls below [10-1000] KB for [1/2/3] mins.

      Sample Screenshot: https://i.imgur.com/8LCi4wi.png

      Just make sure that ‘Don’t Sleep’ is running, while syncing your Dropbox data. The application can be minimized to the system tray.

      Available as portable & installer builds:
      https://www.softwareok.com/?Download=DontSleep

      Info: https://www.softwareok.com/?seite=Microsoft/DontSleep

      > “escape from this loop only when there has been no internet traffic for more than a few seconds”

      Unless your internet connection is reliably stable AND Dropbox always auto resumes data transfer within a few secs after a transient network connection drop, it might be safer for a buffer larger than a few secs — say, at least 15-30 secs ?

      Currently, the minimum cut-off time in ‘Don’t Sleep’ is 60 secs (1 min). If you wish, you can request for smaller time intervals for the aforementioned option. The developer updates the application very regularly.

      Contact: https://www.softwareok.com/?seite=Kontakt

    4. Benjamin said on August 20, 2019 at 9:57 am
      Reply

      Perhaps this is your friend… thing is, if the value is set to high it can take ages for the system to shut down. Besides this, every good syncing algorithm should be able to handle something like a power outage without causing any trouble…

      https://www.howtogeek.com/282062/control-how-long-windows-waits-before-killing-apps-at-shutdown/

      When you shut down your computer, Windows doesn’t shut down immediately. Instead, it gives running applications and services some time to close first. You can control how long Windows waits—and whether it automatically closes running applications or not.

      You shouldn’t normally need to change these settings, but it can be helpful if you’d like to force your computer to shut down more quickly. Some applications may also mess with these settings when you install them, and you might want to reset them to the default values if your shutdown process seems slow.
      Change the Wait Time for Desktop Applications

      There are three registry settings that control what Windows does with running applications when you shut down your computer:

      WaitToKillAppTimeout: When you shut down your PC, Windows gives open applications 20 seconds to clean up and save their data before offering to close them. This value controls how many seconds Windows waits for.
      HungAppTimeout: Windows considers applications “hung” if they don’t respond within 5 seconds and gives you a “force shut down” option. This value controls how many seconds Windows waits before considering applications unresponsive.
      AutoEndTasks: Windows normally displays an “force shut down” button after the number of seconds expires, asking for your permission to close any running applications. If you enable this option, Windows will instead automatically close any applications and shut down without your input.

  4. Henk said on August 20, 2019 at 12:34 pm
    Reply

    Thanks a lot for the tips! I’ll try out both Dshutdown and Dontsleep.

    After installing either Dshutdown or Dontsleep and properly setting it to trigger shutdown after several seconds of no network traffic (how long exactly to be determined by experiment), the most elegant solution might look like this:

    Make a new shortcut for this app (starting it in a minimized window), change the app shortcut icon to the default shutdown icon, and put this new “shutdown” icon in place of the present shutdown icon (which on my taskbar is the leftmost one).

    I hope this may indeed solve the interrupted-sync problem! Thanks again for your helpful comments.

Leave a Reply

Check the box to consent to your data being stored in line with the guidelines set out in our privacy policy

Please note that your comment may not appear immediately after you post it.