TechNet Magazine > Home > Tips > Windows Server 2008 >  Create System Startup / Shutdown and User Logon...
Tip: Create System Startup / Shutdown and User Logon / Logoff Scripts

With Windows Server 2008 you can configure four types of scripts:
Computer Startup Executed during startup
Computer Shutdown Executed prior to shutdown
User Logon Executed when a user logs on
User Logoff Executed when a user logs off

You can write scripts as command-shell batch scripts ending with the .bat or .cmd extension or as scripts that use the Windows Script Host (WSH). WSH is a feature of Windows Server 2008 that lets you use scripts written in a scripting language, such as VBScript, without needing to insert the script into a Web page. To provide a multipurpose scripting environment, WSH relies on scripting engines. A scripting engine is the component that defines the core syntax and structure of a particular scripting language.

Assigning Computer Startup and Shutdown Scripts
Computer startup and shutdown scripts are assigned as part of a group policy. In this way, all computers that are members of the site, domain, or organizational unit—or all three—execute scripts automatically when they’re booted or shut down.

Tips RSS Feed
To assign a computer startup or shutdown script, follow these steps:
1. For easy management, copy the scripts you want to use to the Machine\Scripts\Startup or Machine\Scripts\Shutdown folder for the related policy. Policies are stored in the %SystemRoot%\Sysvol\Domain\Policies folder on domain controllers.
2. In the GPMC, right-click the GPO for the site, domain, or organizational unit you want to work with and then select Edit. This opens the policy editor for the GPO.
3. In the Computer Configuration node, double-click the Windows Settings folder and then click Scripts.
4. To work with startup scripts, right-click Startup and then select Properties. To work with shutdown scripts, right-click Shutdown and then select Properties.
5. Click Show Files. If you copied the computer script to the correct location in the Policies folder, you should see the script.
6. Click Add to assign a script. This opens the Add A Script dialog box. In the Script Name field, type the name of the script you copied to the Machine\Scripts\Startup or the Machine\Scripts\Shutdown folder for the related policy. In the Script Parameters field, enter any command-line arguments to pass to the command-line script or parameters to pass to the scripting host for a WSH script. Repeat this step to add other scripts.
7. During startup or shutdown, scripts are executed in the order in which they’re listed in the Properties dialog box. Use the Up and Down buttons to reposition scripts as necessary.
8. If you want to edit the script name or parameters later, select the script in the Script For list and then click Edit.
9. To delete a script, select the script in the Script For list, and then click Remove.

Assigning User Logon and Logoff Scripts
You can assign user scripts in one of three ways:
  • You can assign logon and logoff scripts as part of a group policy. In this way, all users who are members of the site, domain, or organizational unit—or all three—execute scripts automatically when they log on or log off.
  • You can also assign logon scripts individually through the Active Directory Users And Computers console. In this way, you can assign each user or group a separate logon script.
  • You can also assign individual logon scripts as scheduled tasks. You schedule tasks using the Scheduled Task Wizard.
To assign a logon or logoff script in a group policy, follow these steps:
1. For easy management, copy the scripts you want to use to the User\Scripts\Logon or the User\Scripts\Logoff folder for the related policy. Policies are stored in the %SystemRoot%\Sysvol\Domain\Policies folder on domain controllers.
2. In the GPMC, right-click the GPO for the site, domain, or organizational unit you want to work with and then select Edit. This opens the policy editor for the GPO.
3. Double-click the Windows Settings folder in the User Configuration node and then click Scripts.
4. To work with logon scripts, right-click Logon and then select Properties. To work with logoff scripts, right-click Logoff and then select Properties.
5. Click Show Files. If you copied the user script to the correct location in the Policies folder, you should see the script.
6. Click Add to assign a script. This opens the Add A Script dialog box. In the Script Name field, type the name of the script you copied to the User\Scripts\Logon or the User\Scripts\Logoff folder for the related policy. In the Script Parameter field, enter any command-line arguments to pass to the command-line script or parameters to pass to the scripting host for a WSH script. Repeat this step to add other scripts.
7. During logon or logoff, scripts are executed in the order in which they’re listed in the Properties dialog box. Use the Up and Down buttons to reposition scripts as necessary.
8. If you want to edit the script name or parameters later, select the script in the Script For list and then click Edit.
9. To delete a script, select the script in the Script For list, and then click Remove.


From the Microsoft Press book Microsoft Windows Server 2008 Administrator’s Pocket Consultant by William R. Stanek.

Looking for More Tips?

For more Windows Server tips, visit the TechNet Magazine Windows Server 2008 Tips page.
For more Tips on other products, visit the TechNet Magazine Tips index.
Page view tracker