Software-deployment tools such as Microsoft Systems Management Server (SMS) are a preferred method of software deployment for most organizations. However, your organization might not have the budget to support buying and implementing this type of tool. Other choices are to use a tool that's built into the Windows OS (e.g., Group Policy Objects—GPOs) or a custom logon script. I prefer custom logon scripts because they provide a flexible method for configuring, installing, and maintaining systems. One practical use for logon scripts is to automate deployment of software and patches. Here, I show you how to create a VBScript logon script that does exactly that. You can modify the script to use in your own environment.
The Basic Logon Script
Table 1 lists required and optional features for our logon script. The essential requirement is for the script to install and uninstall software and patches. The script must also let an administrator turn on or off individual software or patch installations. Optionally, the script should display messages, collect information, and configure the OS and applications.
Using these requirements, I created a basic logon script—Install.vbs—which Listing 1 shows. The script reads through an input file that contains commands, executes those commands line by line, and displays installation messages on screen. I chose to use Microsoft Internet Explorer (IE) to display the on-screen messages, although you could use another method to do so.
Install.vbs meets all our essential requirements for a logon script. First, it performs the key requirement of installing and uninstalling software and patches by acting as a wrapper that reads a command from the provided input file and executes it line by line, similar to executing a batch file. The script uses the FileSystemObject object's OpenTextFile method to open and read the commands from the input text file and uses the WScript.Shell object's Run method at callout B in Listing 1 to execute the read command.
For example, suppose that you want to delete all files in a temporary directory, run installpkg1.vbs to install WinZip, update your virus scanner's .dat files by running updatevs.cmd, and install a security update for Microsoft Data Access Components (MDAC). To perform these tasks, you'd create an input file that contains one command per line and save it as a text file called installer_input.txt. When Install.vbs runs, it reads installer_input.txt and executes the commands in it line by line, in the order in which they're listed in the file. The sample text file in Listing 2 shows that the script will execute the Del command, installpkg1.vbs, updatevs.cmd, and the MDAC installation command. (Several lines in Listing 2 wrap to the next line because of space constraints.) In our example, a central server hosts all the installation files, so in the text file I've included the Universal Naming Convention (UNC) path (i.e., the absolute path) to the install share on the server.
The script also performs the second required function: During execution, it displays the installation messages on the user's screen. You can script this display capability in several ways. For example, you could use a WScript.Echo command to pop up a message, or use the WScript.StdOut property to write the output to the console. However, to use either method in unattended mode (i.e., to avoid displaying a pop-up window that the user must click to continue script execution), you need to run the script with the CScript scripting host.
Alternatively, you can use IE to display messages, which is the method I use in Install.vbs. You can use the InternetExplorer.Application automation object to create a new document window and write to the window by using the object's Write method. You can find detailed information about the InternetExplorer.Application object at http://msdn.microsoft.com/workshop/browser/webbrowser/reference/objects/internetexplorer.asp?frame=true.
As callout A in Listing 1 shows, Install.vbs begins by initializing the display-window properties and setting the visible property to true to make the window visible at runtime. The script also stores the new IE document object (the display-window object) in the oDoc variable. The code at callout B then passes to the DocWrite subroutine at callout C the message that will be written in the IE display window.
Install.vbs provides the third essential function for our logon script: It lets you turn an installation on or off at will. You can enable a command's execution simply by adding the command to the input text file. Conversely, deleting a command from the input text file disables execution of the command.
Finally, Install.vbs meets the two optional requirements for the logon script: configuring the OS and applications and collecting information. For example, if you want to change the default WinLogon display message (which appears when a user presses Ctrl+Alt+Delete in Windows NT or later), you'd include in the input text file the command
regedit /s winlogon.reg
where the winlogon.reg file contains the registry configuration that you want to set. To collect information, such as available disk space, you can include in Install.vbs a command to execute a program or a script that gathers such information.