[Previous] [Table of Contents] [Next]

# Creating Scripts

You can prepare a script from scratch using Notepad, the editor in Microsoft Windows, simply by launching Notepad and entering statements using the syntax of the selected script language (as discussed in Chapter 1). Then you store the script program in a script file, as shown in Figure 2-1. For VBScript you use the extension .vbs, for JScript you use the extension .js, and for Microsoft Windows Script Host (WSH) 2 you use the extension .wsf. (For more information about .wsf files, refer to the section "The New .wsf File Format" in Chapter 1.)

> TIP

> In the Save As dialog box, select All Files in the Save As Type drop-down list to see all the script files in the selected folder.

Figure 2-1 Saving a script file in Notepad

## Using Script Templates

Building a script from scratch isn't the best approach, however. For example, if you use the header comments that I recommended in Chapter 1, you must add them explicitly each time you create a new script. Instead, you can use the template files VBScript.vbs and JScript.js to build script files and use the template file WSHfile.wsf for .wsf files. You simply configure Windows so that it recognizes script templates:

1. Open the folder \WSHDevGuide\Chapter01 on the companion CD, and copy the files VBScript.vbs, JScript.js, and WSHfile.wsf to a local folder on your hard drive.

2. In Control Panel, double-click the Tweak UI icon and then click the New tab in the Tweak UI dialog box.

3. Drag each template file from the folder window and drop it on the New tab to create a new entry for the template, as illustrated in Figure 2-2.

4. Click OK to close the Tweak UI dialog box. Tweak UI copies the files to the Windows folder \ShellNew (in Windows 98) or to the folder \Documents and Settings\<user name>\Templates (Windows 2000) and registers the new templates.

Figure 2-2 Registering a script template using Tweak UI

You'll find three new commands—JScript Script File, VBScript Script File, and Windows Script File—on the New shortcut menu, as shown in Figure 2-3. You can use these commands to create a new script file in any folder.

Figure 2-3 Creating a new script file using the shortcut menu

> NOTE

> Tweak UI is a Windows tool for customizing the operating system, and you must install it explicitly. Windows 98 users can find this module on the Windows 98 CD in the \tools\reskit\powertoy folder. Windows 95, Windows NT 4, and Windows 2000 users can download a version of Tweak UI from several Internet sites. (Search http://www.microsoft.com for the most recent version.) To install the tool, browse the directory to find the folder with the Tweak UI installation files. Right-click on the file TweakUI.inf, and choose Install from the shortcut menu. After you install the tool, the Tweak UI icon will appear in the Control Panel folder.