Jump to content

Back to Basics: Windows Shutdown Autostart explained


Karlston

Recommended Posts

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.

 

 

 

Source: Back to Basics: Windows Shutdown Autostart explained  (gHacks - Martin Brinkmann)

Link to comment
Share on other sites


  • Views 885
  • Created
  • Last Reply

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...