You learned in previous chapters how to write scripts for mapping network drives or connecting to a network printer. You know also how to use the FileSystemObject object and its methods (to back up files, for example), and you've learned the techniques for developing scripts that create shortcuts on the Desktop or on the Start menu. You're therefore aware that you can use scripts to customize user systems and automate tasks. What I haven't discussed yet is how to write scripts that are executed during events such as startup, shutdown, logon, and logoff. Since Windows NT 4 supports logon scripts (as batch files, for example) Microsoft has made the effort in Windows 2000 to provide extended support for scripting during startup, shutdown, logon, and logoff.
In Windows 2000 (and even in Windows NT), an administrator can set up any user account in such a way that a logon script runs automatically whenever the user logs on. (You can use customized scripts from previous chapters for that purpose.) To set up a logon script, you take the following steps:
Figure 13-3 The Microsoft Management Console with the Profile property page
After you close the property pages and dialog boxes using the OK button, the settings for this user account are saved. If you haven't done so already, you need to copy the logon script to the logon script path. This path depends on whether the logon script is executed when logging on to a domain or when logging on to a local account. To execute the logon script when logging on to a domain, the script is stored on the primary domain controller. On a Windows NT 4 domain controller, the logon script path is
where systemroot stands for the path to the Windows folder; on a Windows 2000 domain controller, the logon script path is
For local accounts on either Windows 2000 or Windows NT 4, the logon script path is as follows:
If the script is in this logon path, you only need to enter the filename (Logon.vbs, for example) in the Logon Script text box. You can also use a subfolder within the script path to store the logon scripts (so that you can group different logon scripts for user groups, for example). In this case, you must precede the filename with the relative path (such as admins\Logon.vbs).
The logon script will now run automatically whenever that user logs on. The advantage of this approach is that you can assign an individual logon script to each user.
In Windows 2000, you can use WSH script files directly as logon scripts. (You can enter files with the extensions .vbs, .js, and .wsf in the Logon Script text box.) Windows NT 4 supports only logon script files with the extensions .exe, .cmd, and .bat, so you must create a .bat file that launches the WSH logon script, store the .bat file in the script path, and enter the name of the .bat file in the Logon Script text box.
Windows 2000 offers an alternative way to run scripts automatically during user logon or user logoff:
Figure 13-4 MMC with the Scripts property page
Figure 13-5 The Add A Script dialog box
After you close all open dialog boxes using the OK button, the selected script file is executed automatically (independent of the user's account) whenever a user logs on or logs off (depending on which icon you double-clicked).
Windows 2000 allows execution of startup and shutdown scripts independent of user logon or logoff. This comes in handy for machines running without a user currently logged on (servers, for example). If you need a script to be executed automatically during startup or shutdown, take these steps, which are similar to those in the previous section:
After you close all open dialog boxes using the OK button, the selected script file is executed automatically during each system startup or shutdown (depending on which icon you double-clicked).
If Windows 95 or Windows 98 machines are running in a network environment with a Windows NT domain controller, a network administrator can set up logon scripts to be executed in a user or group policy. If the computer is running in a workgroup environment or as a standalone system, you can choose between two approaches for executing scripts automatically during user logon:
Whichever approach you choose, all scripts are executed during each user logon.