In Part I of this book, you learned the basics of VBScript programming, including how to create and execute VBScripts in both the WSH and Internet Explorer execution environments. You also learned about the WSH core object model and the properties and methods associated with its objects. In this chapter, you'll begin work on a collection of desktop management scripts that will allow you to expand your working knowledge of many of the WSH objects.
In this project, you will examine and duplicate a desktop management project recently undertaken by a fictional company named ABC, Inc. ABC, Inc. does radio and newspaper marketing, advertising, and consulting in the central Virginia area. ABC, Inc. is a small company with 50 employees. With only a few exceptions, each of these employees is considered computer savvy.
Currently, each employee in the company has an assigned computer to work from. All the computers are connected to a small Windows domain-based network. The company has a collection of six Windows NT and 2000 servers from which they support a corporate Web site, file and print services, and a customer and projects database. To manage these servers and the Windows network, the company has two IT employees, Rick and Sue. For the most part, things run smoothly on these servers, and the company is very pleased with the way that Rick and Sue maintain things.
However, when it comes to desktop support, things are not going quite so well. Because it has a technically savvy workforce, the company has invested a minimal amount of time and effort on desktop support. Carl, the office manager, and his assistant, Becky, are in charge of corporate desktops. For the most part, their duties have been limited to purchasing and receiving new computers, which they then set up for individual users. After initial setup and configuration, users are left to work out desktop computer problems on their own. Therefore, desktop support at ABC, Inc. can be classified as being loosely supported.
Occasionally, users call Carl or Becky for help with a hardware or software problem that they cannot resolve. This often leads to a visit by Carl or Becky to determine whether something is broken and needs to be replaced of if there is a software or configuration problem that they could solve. Many times Carl and Becky call upon Rick and Sue, who are regarded as the company's computer gurus, for help.
Desktop support is only a part-time task for Carl and Becky, and they paid as little attention to it as possible. Because of this lack of attention, things have become a little messy over the last few years. For one thing, management requires that Carl and Becky shop for the best possible prices each time a new computer is purchased. As a result, the company purchased computers from numerous manufacturers over the years, including IBM, Compaq, Dell, and Gateway. In addition, Carl and Becky now find themselves supporting a number of different Microsoft operating systems, including Windows 98, Workstation NT 4.0, Windows 2000 Professional, and Windows XP Professional.
To make matters worse, users are beginning to find that their computers do not have adequate hardware resources (such as processor, memory, and drive space) to support new applications. As a result, Carl and Becky have noticed a large increase in the amount of time that they have had to dedicate to desktop support in the last six months. After numerous meetings and discussions with the top management, Carl and Becky have finally received authorization to hire a full-time staff member to assume responsibility for managing all corporate desktops. This person is Tom.
Tom started last month and went right to work taking care of existing user problems. It did not take Tom long to come to a number of conclusions, which he quickly documented and passed on to Carl and Becky. Tom also provided them with a formal report in which he identified a number of issues that he felt the company needed to address right away. A brief synopsis of these issues is outlined below.
Management was receptive to Tom's recommendations and decided to implement them. New computers would be purchased in batches of 10, with a complete overhaul of the company's desktop environment in just five months. Dell would be selected as the company's desktop computer vendor. Arrangements were made to purchase 50 new computers, each equipped with 2GHz processors, 256MB of memory, 20GB hard drives, 17-inch monitors, and a preinstalled network adapter. All computers will come with Windows XP Professional and Microsoft Office preinstalled.
With the first batch of computers scheduled to arrive in just three weeks, Tom knows that he will be under a lot of pressure to configure them and get them deployed as quickly as possible. Previously, Carl and Becky took an average of five business days to customize and deploy a newly purchased computer. Given the number of computers that Tom will have to deal with in the coming months, he knows that management would not be pleased with this kind of turnaround. He decides that he wants to set a goal of rolling out 10 computers within four days of their receipt. This will not only impress upper management, but will also provide Tom with more time to assist in training users and help them troubleshoot problems. In addition, it will give Tom more time to work with Rick and Sue to begin training as backup server administrators.
Tom plans to develop a collection of WSH VBScripts to speed up the desktop configuration process, which he refers to collectively as his Desktop Deployment Toolkit. Once developed, these scripts will allow Tom to configure new desktops quickly. These scripts will eliminate problems and issues that result from human error (such as mistyping configuration settings, incorrectly performing procedures, and so on).
To begin, Tom sat down and documented the current desktop setup and configuration process and looked for ways to improve it and speed it up. By the time he was done, Tom broke down the process of setting up and configuring new computers into the following steps.
Figure 10.1: Creating a local administrator account to be used in case of emergencies
Figure 10.2: The Scheduled Tasks folder is to set up and manage scheduled tasks
The first of these disk management tasks to be scheduled is the Disk Cleanup wizard, shown in Figure 10.3. This wizard frees up disk space by deleting noncritical files, including:
Figure 10.3: Using the Disk Cleanup wizard to remove unnecessary files from the computer
The second disk management task to be set up is the Disk Defragmenter utility, shown in Figure 10.4. This utility is used to keep the C: drive on each user's computer defragmented.
Figure 10.4: Setting up the Disk Defragmenter to run on a monthly basis
Figure 10.5: Using the Create Shortcut wizard to create a URL shortcut to the corporate Web site
Note |
A number of desktop customization tasks are not performed until the computer is delivered to the user because these changes are saved in the user's profile and then are stored in the HKEY_CURRENT_USER root key of the Windows registry. In order to make these changes the user's profile must be loaded into memory (that is, the user needs to be logged on). |
Figure 10.6: Configuring the Starfield screen saver to start running after 15 minutes of inactivity
Figure 10.7: Configuring the desktop to display the corporate logo
Figure 10.8: Creating a Standard Applications folder that contains shortcuts to applications used by everyone in the company
Figure 10.9: Adding a shortcut to the Standard Applications folder on the Start menu
Figure 10.10: Using the Add Printer Wizard to set up a connection to the company's network printer
Figure 10.11: Using the Map Network Drive wizard to map a drive connection to the company's shared network drive
After studying the rollout process for a while, Tom determines that he can significantly speed things up by automating key parts of the process using VBScript and the WSH. Tom produces a list of tasks that he considers to be candidates for automation and that he thinks he'll be able to write within the next three weeks.
He then organizes these tasks into logical groups, thinking that he will focus on automating one group of related tasks at a time. Table 10.1 shows the list that Tom put together.
Type of Task |
Description |
---|---|
Desktop customization |
Customize the Windows desktop by adding a shortcut to the corporate Web site. Set up each user's screen saver to kick in after 15 minutes and to display the Starfield screen saver with password protection enabled. Set the Windows background to display the corporate logo. |
Start menu and taskbar |
Create a Standard Applications folder and populate it with shortcuts to Microsoft Word, Adobe Acrobat Reader, Paint Shop Pro, WinZip, and an FTP application. Customize the Quick Launch toolbar by adding a link to the Windows Calculator and WinZip applications. Customize the Start menu by adding the Standard Applications folder to the Start menu's All Programs folder. |
Task scheduling |
Schedule the execution of the Disk Cleanup wizard once a month. Schedule the execution of the Disk Defragmenter utility once a month. |
Network connections |
Set up a network printer connection to the corporate network printer pool. Set up a mapped drive to the corporate file server. |
Account management |
Add a local administrative maintenance user account to each computer. |
As a preliminary task, Tom decides to start by researching the WSH objects and Windows utilities and commands that he'll need to work with to automate each task. As a design strategy, Tom decides that he wants to break down tasks into small scripts and that scripts should be limited to performing no more than one or two tasks. This will help to facilitate rapid script development and testing, which is important to Tom because he only has a few weeks until the first batch of computers are scheduled to arrive.
Desktop Customization
Tom has broken down the desktop customization tasks into two separate tasks, as shown below.
Tom has determined that to create a URL shortcut to the corporate Web site, he will need to make use of the WSH WshUrlShortcut object, which provides the ability to specify a URL via its TargetPath property. In addition, he'll need to use the WshShell object's SpecialFolders property in order to establish a reference to the Windows desktop.
In order to programmatically configure the Windows screen saver and desktop background, Tom has learned that he needs to make changes to the Windows registry. To do this, he will need to use the WSH WshShell object's RegWrite() method in order to modify screen saver and desktop wallpaper values stored in the HKCUControl PanelDesktop key.
In order for changes made to the desktop wallpaper to take effect, Tom will need to have the user log off and back on again. Tom has discovered that Windows XP provides the logoff.exe command line utility, which he will be able to use within a script to automatically log off the user.
Start Menu and Taskbar
Tom has broken down the Start menu and taskbar tasks into three separate tasks:
Tom has discovered that in order to create a folder, he'll need to learn to work with the VBScript run-time FileSystemObject. To create a desktop shortcut, Tom needs to begin by establishing an instance of the WshShell object. Then he needs to access the Windows Desktop special folder using the WScript object's SpecialFolders property. In addition, Tom needs to use the WshShell object's CreateShortCut() to finish creating the shortcut.
To configure the Quick Launch toolbar, Tom has discovered that he needs to configure and add a shortcut to it. In order to do this, he'll need to learn to work with another special folder called AppData. In addition, he'll need to learn how to work with special folders that represent the Start menu and the All Programs menu in order to configure the Start menu.
Task Scheduling
Tom has identified two disk management tasks that he needs to set up to run every 30 days. These utilities are listed below.
In order to programmatically interact with the Windows scheduler service, Tom plans to use the Windows At command. He has discovered that in order to execute this command from within a WSH VBScript, he'll need to learn how to use the WshShell object's Run() method.
Tom has also learned that he can use the defrag.exe command line utility to defrag hard disk drives. He can pass this utility arguments that will allow it to run silently in the background. In addition, he can use the cleanmgr command line utility to run the Disk Cleanup utility as a background task.
Network Connections
Tom needs to set up two network connections as part of the computer setup and configuration process. The network resources for which the connections are to be made are outlined below.
In order to set up these two network connections, Tom needs to learn how to work with the WSH WshNetwork object. Specifically, he'll need to use the following WshNetwork object methods:
Account Management
Tom plans to use the Windows net user command to create a local user account. In order to do so, he'll need to use the WshShell object's Run() method to be able to execute the commands. Once the new account has been added to the local computer, he'll need to use the WshShell object Run() method again to add the new account to the administrator's group. To complete this task, he plans to execute the Windows net localgroup command.
Now that Tom has an idea of the VBScripts that he wants to develop and the commands, objects, methods, and properties that he'll need to use in order to write them, he decides to develop a brief implementation plan. In this plan, he decides to develop 10 separate VBScripts, one for each task number in the plan.
Tom then presents this plan to Carl, the office manager, for approval so that he can begin writing the scripts as quickly as possible. Table 10.2 shows the implementation plan that Tom developed.
Task No. |
Task Type |
Description |
---|---|---|
0100 |
Desktop |
Configure a shortcut to the corporate Web site. |
0110 |
Desktop |
Set up a password-protected screen saver with a 15-minute delay and configure the Windows background to display the corporate logo. |
0200 |
Start menu and taskbar |
Create a Standard Applications folder and populate the Standard Applications folder with application shortcuts. |
0220 |
Start menu and taskbar |
Add application shortcuts to the Quick Launch toolbar. |
0230 |
Start menu and taskbar |
Add application shortcuts to the All Programs menu located on the Start menu. |
0300 |
Scheduling |
Schedule the execution of the defrag.exe utility. |
0310 |
Scheduling |
Schedule the execution of the cleanmgr utility. |
0400 |
Network |
Automate the setup of the network printer connection. |
0410 |
Network |
Automate the setup of a mapped drive to the corporate file server. |
0500 |
Account Admin |
Create a local administrative maintenance user account. |
Upon reviewing Tom's plan, Carl happily approved it. However, Carl wanted to know how Tom planned on incorporating these scripts into the rollout process. Tom explained that although the steps that make up the overall process would remain unchanged, he would now be able to execute them more quickly while eliminating errors that often occurred in the past.
Tom told Carl that he plans on copying all the scripts onto a floppy disk, which he will insert into each computer when it is first placed on the build table. He will then run each script representing a build-table task from the floppy disk. Then he will take a copy of the floppy disk with him when he delivers each computer. After getting the user to log in, Tom will insert the floppy disk and run the remaining scripts. Not only will this process reduce the disruption imposed on each user, but it will also make it possible for Tom to deploy all the computers, once removed from the build table, in a single day.
In this chapter, you were introduced to ABC, Inc. You reviewed the challenges that the company faces regarding the support and deployment of desktop computers. In addition, you observed as Tom, the company's new desktop support analyst, devised a plan for streamlining the desktop deployment process by developing VBScripts that automated a number of manual tasks. In the next five chapters, you will get the opportunity to follow along as Tom implements his plan by developing these scripts.
Part I - Introducing Microsoft VBScriptBasics
Part II - Professional Project 1 Desktop Administration Using VBScript and the WSH
Part III - Professional Project 2 Analyzing Application Logs
Part IV - Professional Project 3 Creating a Centralized Report Management Station
Part V - Professional Project 4 Reporting Application Summary Data via the Web
Part VI - Introducing Microsoft VBScriptBasics