Script policies control the behavior and assignment of computer and user scripts. Four types of scripts can be configured:
-
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 these scripts as command-shell batch
scripts, Windows scripts, or Windows PowerShell scripts. Batch scripts
use the shell command language. Windows scripts use Windows
Script Host (WSH) and are written in a scripting language such as
Microsoft Visual Basic Scripting Edition (VBScript) or Microsoft
JScript. Windows PowerShell scripts are written in the Windows
PowerShell language. Note that policy preferences can in many cases
eliminate the need to use computer and user scripts.
Controlling Script Behavior Through Policy
Policies that control script behavior are found under the
Administrative Templates policies for Computer Configuration under
System\Scripts and the Administrative Templates policies for User
Configuration under System\Scripts. Through policy, you can control the
behavior of startup, shutdown, logon, and logoff scripts. The key
policies that you’ll use are described in Table 1. As you’ll see, there are numerous options for configuring script behavior.
Table 1. Computer and User Script Policies
POLICY TYPE |
POLICY NAME |
DESCRIPTION |
---|
Computer |
Display Instructions In Shutdown Scripts As They Run |
Displays shutdown scripts and their instructions as they execute. |
Computer |
Display Instructions In Startup Scripts As They Run |
Displays startup scripts and their instructions as they execute. |
Computer |
Run Startup Scripts Asynchronously |
Allows the system to run startup scripts simultaneously, rather than one at a time. |
Computer |
Run Windows PowerShell Scripts First At Computer Startup, Shutdown |
Determines whether Windows PowerShell scripts are run before other types of scripts at startup and shutdown. |
Computer |
Specify Maximum Wait Time For Group Policy Scripts |
Sets the maximum time to wait for scripts to finish running. The default value is 600 seconds (10 minutes). |
Computer/User |
Run Logon Scripts Synchronously |
Ensures the system waits for logon scripts to finish before displaying the Windows interface. |
Computer/User |
Run Windows PowerShell Scripts First At User Logon, Logoff |
Determines whether Windows PowerShell scripts are run before other types of scripts at logon and logoff. |
User |
Display Instructions In Logoff Scripts As They Run |
Displays logoff scripts and their instructions as they execute. |
User |
Display Instructions In Logon Scripts As They Run |
Displays logon scripts and their instructions as they execute. |
User |
Run Legacy Logon Scripts Hidden |
Hides logon scripts configured through the System Policy Editor in Microsoft Windows NT 4. |
Although you can control script behavior in many ways, you’ll usually want scripts to behave as follows:
-
Windows PowerShell scripts should run first. -
Logon and startup scripts should run simultaneously (in most cases). -
All scripts should be hidden rather than visible. -
The system should wait no more than 1 minute for a script to complete (in most cases).
To enforce this behavior, follow these steps:
-
Access Group Policy for the computer you want to work with. Next,
access the Administrative Templates policies for Computer Configuration
under System\Scripts. -
Double-tap or double-click Run Windows PowerShell Scripts First At
Computer Startup, Shutdown. Select Enabled, and then tap or click OK. -
Double-tap or double-click Run Windows PowerShell Scripts First At User Logon, Logoff. Select Enabled, and then tap or click OK. -
Double-tap or double-click Run Logon Scripts Synchronously. Select Disabled, and then tap or click OK. -
Double-tap or double-click Run Startup Scripts Asynchronously. Select Enabled, and then tap or click OK. -
Double-tap or double-click Display Instructions In Startup Scripts As They Run. Select Disabled, and then tap or click OK. -
Double-tap or double-click Display Instructions In Shutdown Scripts As They Run. Select Disabled, and then tap or click OK. -
Double-tap or double-click Specify Maximum Wait Time For Group Policy
Scripts. Select Enabled, and then enter a value of 60 for the wait time
in the Seconds box. Tap or click OK. -
Access the Administrative Templates policies for User Configuration under System\Scripts. -
Double-tap or double-click Run Legacy Logon Scripts Hidden. Select Enabled, and then tap or click OK. -
Double-tap or double-click Display Instructions In Logon Scripts As They Run. Select Disabled, and then tap or click OK. -
Double-tap or double-click Display Instructions In Logoff Scripts As They Run. Select Disabled, and then tap or click OK. -
Double-tap or double-click Run Windows PowerShell Scripts First At User Logon, Logoff. Select Enabled, and then tap or click OK.
Assigning Computer Startup and Shutdown Scripts
Computer startup and shutdown scripts can be assigned as part of
Group Policy. In this way, a computer and all its users—or all computers
that are members of the site, domain, or OU—execute scripts
automatically when they’re started or shut down.
To assign computer scripts, follow these steps:
-
For easy management, copy the scripts you want to use to the
Scripts\Startup or Scripts\Shutdown folder for the related policy.
Scripts are stored in the %SystemRoot%\Sysvol\Sysvol\%UserDnsDomain%\Policies\GUID\Machine folder on domain controllers and %WinDir%\System32\GroupPolicy\Machine on workstations running Windows 8. -
Access the Group Policy console for the resource you want to work
with. Then access policies for Computer Configuration under Windows
Settings\Scripts. -
To work with startup scripts, press and hold or right-click Startup
and then select Properties. To work with shutdown scripts, press and
hold or right-click Shutdown and then select Properties. Next, tap or
click Show Files. If you copied the computer scripts to the correct
location, you should see the scripts you want to assign. -
Tap or click Add to assign a script.
This opens the Add A Script dialog box. For the Script Name, type the
name of a script you copied to the Scripts\Startup or the
Scripts\Shutdown folder for the related policy. For the Script
Parameters, 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. -
During startup or shutdown, scripts are executed in the order in which they’re listed in the Properties dialog box. Select a script name, then tap or click Up or Down to reposition the script as necessary. -
If you want to edit the script name or parameters later, select the script in the scripts list, and then tap or click Edit. -
To delete a script, select the script in the scripts list and then tap or click Remove.
Assigning User Logon and Logoff Scripts
User scripts can be assigned as part of Group
Policy. In this way, all users who access a computer or are members of
the site, domain, or OU execute scripts automatically when they log on
or log off.
To assign user scripts, complete the following steps:
-
Copy the scripts you want to use to the Scripts\Logon or the
Scripts\Logoff folder for the related policy. User scripts are stored in
the %SystemRoot%\Sysvol\Sysvol\%UserDnsDomain%\Policies\GUID\User folder on domain controllers and under %WinDir%\System32\GroupPolicy\User on workstations running Windows 8. -
Access the Group Policy console for the resource you want to work with. Then access policies for User Configuration under Windows Settings\Scripts. -
To work with logon scripts, press and hold or right-click Logon and
then tap or click Properties. To work with logoff scripts, press and
hold or right-click Logoff and tap or click Properties. Next, tap or
click Show Files. If you copied the user scripts to the correct
location, you should see the scripts you want to assign. -
Tap or click Add to assign a script. This opens the Add A Script
dialog box. For the Script Name, type the name of a script you copied to
the Scripts\Logon or the Scripts\Logoff folder for the related policy.
For the Script Parameter, 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. -
During logon or logoff, scripts are executed in the order in which
they’re listed in the Properties dialog box. Select a script name and
tap or click Up or Down to reposition scripts as necessary. -
If you want to edit the script name or parameters later, select the script in the Scripts list, and then tap or click Edit. -
To delete a script, select the script in the Scripts list, and then tap or click Remove.
|