Handling Omitted Switches
An ideal script would accept command-line switches and use pop-up dialog boxes to prompt you for missing information. Such a script would provide the best of both worlds: command-line switches so that you can easily launch the script and provide the necessary parameter values, and pop-up dialog boxes for any required switches that you've forgotten. Incorporating this capability is easy: Just add a few Do...Loop statements that check for missing values after the For Each...Next loop. Listing 3 shows an example. You'll need to add a Do...Loop construct for each required parameter.
Listing 4 shows a new version of DisableUser.vbs called NewDisableUser.vbs that incorporates both command-line and pop-up dialog capabilities. Callout A in Listing 4 shows the added code. NewDisableUser.vbs includes three command-line switches:
- -s: for the name of the server that contains the user's home directory
- -u: for the user account name
- -d: for the name of the domain in which the user's account is located
This script works in Windows 2000 and Windows NT domains. Note that NewDisableUser.vbs uses Microsoft Active Directory Service Interfaces (ADSI).
As you can see, adding command-line switch capability to your scripts makes them much more flexible. When a script supports command-line switches, you don't have to open and modify the script each time you use it. Instead, you can quickly launch it and provide the necessary information at the command line. And when a script incorporates pop-up dialog boxes that prompt you for missing information, you can even launch it by simply double-clicking the script and providing parameters in the pop-up dialog boxes.