If you’re just getting started with the Windows Script Host and its scripting languages, you may find the open environment in which you develop your scripts a bit distracting. By open environment, I mean that there’s no single application that you use to develop and test your scripts. In this Daily Drill Down, I’ll introduce you to SynEdit, a freeware program that can make it easier for both the beginner and the advanced user to create scripts. I’ll also show you how you can customize it for working with Windows Script Host and its scripting languages.
Learn more about Windows Script Host
These features by Greg Shultz will get you started scripting with Windows Script Host:
- “Getting started with Windows Script Host”
- “Create a file renaming script with Windows Script Host”
- “Automate ping to test a range of IP addresses with this VBScript program”
- “Automating IPConfig in Windows NT/2000 using Windows Scripting Host”
Open scripting vs. integrated development environments
You can create a script in any text editor, such as Notepad. But to test your script, you have to leave Notepad, open Windows Explorer, locate the script file, and then double-click it in order to run the script. Then, if you have questions about an error message or need more information on the scripting language features, you have to access the Start menu to locate and open the Help file. In between each of these steps, you’re probably switching back to Notepad to edit or study your script. All of this switching back and forth between applications can be distracting and problematic—especially if you’re new to scripting and Windows Script Host.
On the other hand, most real programming languages, such as VBScript’s older brother Visual Basic, actually come with an integrated development environment (IDE) that provides programmers with a single user interface in which to create, open, save, test, and debug programs. Being able to perform all the associated operations from within one application allows you to stay more focused on the task at hand—in this case, developing your script.
Fortunately, there are a number of programming tools out there that are designed to aid you in creating and testing scripts. While I haven’t yet found a programming tool specifically designed for Windows Script Host and its scripting languages, I did track down a freeware program called SynEdit, from MKIDesign. SynEdit is very easy to use, provides many of the features found in an IDE, and is very customizable. This means that with a little work, SynEdit can be transformed into a Windows Script Host IDE. Furthermore, SynEdit works in all versions of Windows.
Getting and installing SynEdit
Because SynEdit is freeware, anyone can download and begin using all of its features right away. To get a copy of SynEdit, just point your browser to the Downloads.com site. In addition to downloading the SynEdit program, you’ll also want to download the Windows Script Host ClipText library files.
Once you download SynEdit, unzip the file and run Setup to install the program. However, for now, just hold onto the .zip file (Wsh.zip) containing the Windows Script Host ClipText library files. I’ll explain what to do with them later in this Daily Drill Down.
The Windows Script Host documentation
To follow along with this article, you’ll also need the documentation files for Windows Script Host, VBScript, and JScript. If you haven’t already downloaded and installed these files, you can use the links listed below:
If you’re using Windows 95 or Windows NT, you’ll need to have Internet Explorer 4.x installed to use these documentation files. You’ll also need to download and install the HTML Help Installation And Update Package 1.32.
Taking a quick tour of SynEdit
Before I explain how to customize SynEdit, let’s take a look around so you’re familiar with the program’s user interface. Keep in mind that in this brief tour, I won’t touch on all of SynEdit’s features. However, SynEdit comes with a detailed Help file that you can explore to learn more about the program.
To begin, launch SynEdit from the Start menu. Once SynEdit is running, you’ll see a Window like the one shown in Figure A.
|SynEdit’s user interface has three main sections.|
As you can see, SynEdit’s user interface has three main sections. On the left is a File Browser window, which allows you to quickly and easily locate and open your script files. In the center is the Text Editor window, where you’ll actually type your scripts. SynEdit allows you to open more than one document at a time. In fact, you can open up to 255 documents at one time, if you want to. On the right, you’ll find the ClipText window, which provides you with a timesaving feature that allows you to easily enter programming language keywords into your script just by clicking the term in the list.
Both the File Browser and the ClipText windows minimize to make more room for the Text Editor window. To minimize them, just click once on the title bar of each window. When you do, the Text Editor window will expand. You can then maximize the windows by again clicking once on the title bar.
Right below the three windows is the Status bar, which among the standard items displays the Documents tabs for switching between each open document and the Syntax Profile selector. I’ll come back to the Syntax Profile in a moment.
You’ll also notice that SynEdit has five toolbars in two rows: the standard toolbar and four specialized toolbars. The top row contains the Standard, Compiler Functions, and Cursor Status toolbars. The second row contains the Edit Functions and Search Functions toolbars. SynEdit takes advantage of tool tips, so you can hover you mouse pointer over each of the buttons to learn its function.
Adding the Windows Script Host Help files to SynEdit
When you’re creating your script files, the Windows Script Host and scripting language documentation files can come in handy for studying the language reference or looking up other information. Fortunately, SynEdit provides you with a way to run external programs. You can configure SynEdit to open the Windows Script Host and scripting language documentation files, which are in the compiled HTML Help file format.
To add the documentation files to SynEdit, select the Configure Utilities command from the Utilities drop-down menu. You can also click the Configure Utilities button on the Compiler Functions toolbar. When you see the Configure Utilities dialog box, click the Add Program button. Once the Add/Edit Utility dialog box appears, type a description in the Utility Name text box and then enter the name of the Help engine’s executable file followed by the path to the documentation file, as shown in Figure B.
|You can use SynEdit to access the Windows Script Host documentation files.|
The file Hh.exe is an executable file for the HTML Help engine that comes with Windows 98 and Windows 2000. It is added to Windows 95 and Windows NT when you install Internet Explorer 4.x. The paths to individual documentation files are listed below. (Keep in mind that the path to the documentation file must be enclosed in double quotes in the Command Line text box.)
- C:\Program Files\Microsoft Windows Script\JSdocs\JS55.CHM
- C:\Program Files\Microsoft Windows Script\VBSdocs\VBS55.CHM
- C:\Program Files\Microsoft Windows Script\WSHdocs\WSH.CHM
Once you fill in the Add/Edit Utility dialog box, click OK. You can repeat these steps to add the other documentation files to SynEdit.
Customizing the ClipText list
SynEdit’s ClipText feature is designed to provide you with quick access to common programming language keywords. When you need to enter a keyword into your script, you just select it from the ClipText list, and it’s automatically inserted into your script—no typing involved. Another advantage to the ClipText list is that it provides you with a quick reference list of all the available keywords in a particular scripting language.
By default, SynEdit comes with ClipText library files for 34 programming languages. Unless you’re a master programmer, you really don’t need that many. In fact, chances are that the only ClipText library files you’ll want are those that pertain to programming in the Windows Script Host environment. Therefore, to make the ClipText window less cluttered, you’ll want to remove the library files for those programming languages that you won’t ever use. You’ll then want to add the library files for the Windows Script Host, which are contained in the Wsh.zip file you downloaded from the MKIDesign Web site.
The ClipText library files are simple text files that are stored in the C:\Program Files\SynEdit\ClipText folder. Once you access that folder in Windows Explorer, you can go through the list of files and eliminate those you won’t use. You can delete them, move them to another folder, or archive them in a .zip file.
Once you’ve removed the unwanted files, you can unzip the Wsh.zip file and then copy the Windows Script Host ClipText library files to the C:\Program Files\SynEdit\ClipText folder. The .zip file contains the following ClipText library files:
- VBScript Statements
- VBScript Functions
- VBScript Constants
- VBScript Objects
- VBScript Methods
- VBScript Properties
- JScript Statements
- JScript Functions
- JScript Objects
- JScript Methods
- JScript Properties
- WSH Objects
- WSH Methods
- WSH Properties
Planning a Syntax Profile
When you’re creating your scripts, it’s easy to lose track of where specific commands begin and end. This can easily cause even the most experienced programmer to leave out an important keyword in a command. Such an omission can result in numerous error messages in the testing phase and cause a lot of frustration. To make it easy for programmers to keep track of specific commands, many IDEs provide color-coding of certain keywords. SynEdit allows you to create what it calls Language Profiles or Syntax Profiles (they’re actually called both in the program), which will automatically apply color-coding to your scripts based on keywords and delimiters.
SynEdit comes with 37 of these Syntax Profiles, which can make it difficult to find the one that you want. Like the ClipText library files, I suggest that you begin by pruning back the Syntax Profiles before you add your own. To do so, launch Windows Explorer and access the C:\Program Files\SynEdit\Profiles folder. You can go through the list of Syntax Profiles and eliminate those you won’t use.
Since Statements make up the meat of a script and most scripts use a combination of Statements to perform their task, your VBScript and JScript Syntax Profiles will be made up of the language’s Statements. If you want, you can also add Functions, Objects, Methods, and Properties to your Syntax Profile. However, you’ll get the most benefit from color-coding the language’s Statements.
Creating a Syntax Profile
Creating a Syntax Profile is easy. For this example, I’ll explain how to create a Syntax Profile for VBScript. However, you can use the same steps to create a Syntax Profile for JScript. You won’t need to create a Syntax Profile for Windows Script Host’s Objects, Methods, and Properties.
To create a Syntax Profile, complete with editor preferences, from the drop-down File menu, select Preferences | Editor Setup. When you see the Editor Options dialog box, click the Keywords tab, as shown in Figure C. Then, click the Import Keyword List button. When you see the Import Keyword Lists dialog box—basically a standard Open dialog box—select All Files In The Files Of Type drop-down list box and then navigate to the C:\Program Files\SynEdit\ClipText folder. Once you access that folder, locate and select the VBScript Statements file and click Open. When you do, you’ll see the list of Statements appear in the Keyword List 1 panel.
|You’ll use the Import Keyword Lists button to add the language Statements to the Syntax Profile.|
If you want to add Functions, Objects, Methods, and Properties to your Syntax Profile, you’ll want to add Functions to the Keyword List 2 panel and Objects, Methods, and Properties to the Keyword List 3 panel, which you can access by clicking the respective tabs. However, you’ll have to add each individual keyword manually by clicking the Add Keyword button and typing or pasting the keyword in the resulting dialog box. Unfortunately, the Import Keyword Lists feature only works for Keyword List 1 panel.
Next, select the Delimiting Bracers tab and add the appropriate braces and comment marks in the text boxes. Since VBScript doesn’t use braces or brackets to delimit sections of code, you can simply enter the comment marker in the Start text box and the special SynEdit code \n in the End text box, as shown in Figure D.
|For VBScript, you can simply enter the comment marker in the Delimiting Bracers tab.|
To continue, click the Editor Preferences tab. Here, you can configure the way that you want the editor to work. I suggest that you select those options that are selected in the Editor Usability Options panel shown in Figure E.
|You’ll use the settings on the Editor Preferences tab to configure how you want the editor to function.|
The default font in SynEdit is Courier New, but you can choose a different font if you wish. You should choose a simple font—preferably one that is nonproportional. You can leave the default selection in the Editor Tab Behaviour panel. If you wish, you can opt to have SynEdit display an icon in the system tray next to the clock.
At this point, click the Color Setup tab, as shown in Figure F, and select the colors that you want to use for color-coding your script. I suggest that you use bright colors, as they’ll make your keywords stand out better. Be sure to select both check boxes in the Color Coding Options panel.
|SynEdit allows you to choose which colors you want to use to color-code your scripts.|
To complete the Syntax Profile configuration, click the Default Profiles tab, as shown in Figure G, and click the Export Current Settings As Profile button. Then, save the file as VBScript Syntax Profile—don’t type any file extension. Next, click the Apply This Profile button. When you do, the Editor Options dialog box will close.
|As the last step, you’ll save and apply your new Syntax Profile.|
Configuring language recognition
The last thing you need to do to construct your Windows Script Host IDE is to establish the language recognition. This allows SynEdit to be able to identify a script file by its file extension when you open it and load the correct Syntax profile.
To begin, from the File drop-down menu, select the Preferences | Language Recognition command. When you see the Configure Language Recognition dialog box, click the Add Extension button to open the Add/Edit Syntax Association dialog box. At this point, type the extension, select the correct syntax profile, and click OK. Then, click OK to close the Configure Language Recognition dialog box.
Using SynEdit as an IDE
Now that you’ve configured SynEdit to work like an IDE, you’re ready to take advantage of the features that will make developing your scripts much easier. Let’s take a closer look at those features indicated in Figure H.
As you can see, Figure H shows the RenameFiles.vbs script loaded into SynEdit so you can see how helpful having a script color-coded can be in quickly evaluating your statements. You’ll also notice that the File Browser and ClipText windows are minimized to make more room for working in the editor window.
Now, when you’re using SynEdit to create a new script, the first thing that you’ll want to do is click the Syntax Profile drop-down list (labeled number 1 in Figure H) and select the VBScript Syntax Profile. Doing so will enable the color-coding feature.
As you’re creating your script, you can easily access the documentation files simply by pulling down the Utilities menu (labeled number 2 in Figure H) and selecting the appropriate command. When you do, the Help system will launch and load the appropriate documentation file. Keep in mind that the Help file will most likely appear in the background behind the SynEdit window, and you’ll have to bring it to the foreground by clicking the icon on the taskbar.
While you’re working on your script, you may discover that you need to make changes to your Syntax Profile. If so, you can click the Edit Profile button on the Compiler Functions toolbar (labeled number 3 in Figure H). When you do, you’ll see a standard Open dialog box where you can locate and open your Syntax Profile. You can then make the changes in the Edit Existing Profile dialog box and then resave the profile.
When working on a script, you’ll inevitably need to make changes to the text—maybe to correct a misspelling or to rename a variable. In this situation, you’ll find the Search And Replace button (labeled number 4 in Figure H) on the Search Functions toolbar to be invaluable.
Once you complete your script and are ready to test it, you can click the Open In Default Application button (labeled number 5 in Figure H). When you do, SynEdit will shell out to Windows and launch your script just as if you had double-clicked the file from within Windows Explorer. If your script is error free, it will run. If it contains errors, you’ll see the Windows Script Host error dialog box appear on top of the SynEdit window, making it very easy to study both the error message and your script.
As you study the error message, you’ll see that it indicates the exact location of the cause of the error with a line number and a character number. If you were troubleshooting the error in Notepad, you would manually have to count the line and character numbers. However, in SynEdit, you can quickly track down the location of the cause of the error by keeping an eye on the Cursor Status toolbar (labeled number 6 in Figure H) as you scroll through your script.
Creating scripts for the Windows Script Host using the open environment can be tricky for beginners and advanced users alike. In this Daily Drill Down, I’ve shown you how to customize the freeware programming editor SynEdit to work like an IDE. I then showed you how to take advantage of SynEdit’s features when creating a script.
Greg Shultz is a freelance Technical Writer. Previously, he has worked as Documentation Specialist in the software industry, a Technical Support Specialist in educational industry, and a Technical Journalist in the computer publishing industry.