 Getting started with VbsEdit

VbsEdit is a dedicated editor for Windows Scripting Host development. VbsEdit dramatically reduces the time you spend writing and debugging .vbs scripts.

If you're new to VbsEdit, here's the information you need to get started :

Editing scripts

Auto completion
Getting dynamic help
Inserting a WMI script
Printing
Setting bookmarks
Using the Object browser
Using code snippets

Running and Debugging scripts

Running scripts
Using the debugger
Setting arguments
Setting breakpoints
Stepping through scripts
Watching variables
Errors and troubleshooting

Convert Script Into Executable

Convert Into Executable


 Auto Completion

List members

The Members list displays valid member variables or functions for the class or object to the left of the insertion point.

Example:
1) Create a new script
2) Type WScript.
3) The members list pops up.

Parameters info

When you are typing a object method, sub or function, you can display a ToolTip containing the complete function prototype, including parameters. This feature is invoked when you type in the opening paren ( or a space character.

Complete word (Alt+Right Arrow)

Complete word types the rest of a variable, method, or function name once you have entered enough characters to disambiguate the term.

Type the first few letters of the name, and then press ALT+RIGHT ARROW.

If what you have typed has more than one possible match or no match at all, then invoke Complete Word to display the Members list, which you can then use to find the term and insert it into your code.

You can invoke the Complete Word feature as follows:

  • On the Edit menu, click Complete Word.
  • Use the ALT+RIGHT ARROW keyboard shortcut.
  • Right-click the text editor and click Complete Word from the shortcut menu.

How does Vbsedit associate a type library with a ProgID ?

1. Given a ProgID (for example, "scripting.filesystemobject"), Vbsedit looks up its associated CLSID in the registry
for example HKEY_CLASSES_ROOT\Scripting.FileSystemObject\CLSID = {0D43FE01-F093-11CF-8940-00A0C9054228}

2. Then, Vbsedit looks up the associated type library (the type library's GUID should be registered under the CLSID)
for example HKEY_CLASSES_ROOT\CLSID\{0D43FE01-F093-11CF-8940-00A0C9054228}\TypeLib={420B2830-E718-11CF-893D-00A0C9054228}

3. Then, Vbsedit looks up the library path in the registry :
HKEY_CLASSES_ROOT\TypeLib\{420B2830-E718-11CF-893D-00A0C9054228}\1.0\0\win32=C:\WINNT\system32\scrrun.dll

If the type library is not registered under the CLSID, Vbsedit browses all type libraries that are registered under the HKEY_CLASSES_ROOT\TypeLib key, and tries to locate a library that describes the ProgID class.

Select References from the Tools menu to associate a type library with a ProdID.


Dynamic help

Getting Dynamic help

Help File

Select a keyword in your script and hit F1 to jump to the related section in Microsoft Scripting documentation.

This feature requires Windows Script Documentation

Troubleshooting

By default, Vbsedit reads the following registry key to locate the documentation installation directory:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Scriptdoc\Installdir

If this key doesn't exists, or if the directory doesn't contain any .chm file, Vbsedit prompts the user to select a .chm file.

To specify a different help file, select Options from the Tools menu and click on the Help tab.

Search the web

Select a keyword in your script and hit F7 to search the web for that keyword.

By default, Vbsedit search the web with Google.

To specify a different search engine, select Options from the Tools menu and click on the Help tab.


WMI

Insert a WMI script

  • On the Snippets menu, click WMI.
  • Select a WMI class from the list

Vbsedit automatically loads the Win32 WMI classes (for example, Win32_SoundDevice and Win32_NetworkAdapter) into a list control.

After Vbsedit finishes loading, you simply select the desired class and you have a script that returns information from, say, Win32_SoundDevice or Win32_NetworkAdapter.


Printing

 To print a script

On the File menu, click Print

Notes

  • If you need to adjust margins or create custom headers and footers, copy your code to the clipboard and paste it into Microsoft Word or any similar software.


 Setting bookmarks

While editing or debugging scripts, you can set bookmarks on lines, which allows you to return quickly to that line later.

To set or clear bookmarks

  • Move to the line where you want the bookmark, and then press CTRL+F2 to toggle the bookmark on and off.

    When a bookmark is set, Vbsedit marks it with an blue icon in the margin.

  • Press CTRL+SHIFT+F2 to clear all bookmarks.

To move between bookmarks

  • Press F2 to move the next bookmark, or SHIFT+F2 to move to the previous bookmark.


Using the Object Browser

 Object browser

The Object Browser allows you to examine objects (classes, interfaces, enums, and so forth) and their members (properties, methods, events, variables, constants, enum items, and so forth) from various components. These components can be classes in your script, or referenced components within your scripts.

Toggle the Object browser button in the toolbar to display the Object browser.

The Active Script tree item lists all classes in your script.

Double-click a function or sub to automatically jump to the associated line in the current script.

Which type libraries does Vbsedit display in the object browser ?

Vbsedit scans the current script for referenced ProgID (occurences of "createobject").


Code snippets

During script development, you might come across a situation where you need to write the same code repeatedly with just a few changes. VBsEdit 3.0 is coming up with a new feature called code snippets, which will help developers to insert code snippets from a snippet store into the script with just a few key strokes.

A code snippet is a fragment of code or text that you can store and reuse many times. Using code snippets feature, you can store frequently used code in a particular folder and you can reuse this code wherever you want with just a few key strokes. In addition to being able to use a selection of pre-defined code snippets, VbsEdit 3.0 allows you to create new snippets, delete unused snippets, and modify existing snippets.

How to create a new code snippet

1. Select a piece of code in your script
2. Choose "Snippets" > "Add to Code Snippets"
3. Enter a name for this code snippet
4. Enter a shortcut for this code snippet (this shortcut will be used to insert the code snippet)
4. Create or select a folder to store this code snippet

How to insert a code snippet in your script

You can insert a code snippet in your script in a variety of ways :

  • Type the snippet shortcut and hit F4
  • Select the snippet name in the Snippets menu
  • Select the snippet name in the context-menu
  • Select the snippet name from the snippet button in the toolbar

Snippets Fields

The literal names enclosed within {...} will become special fields when the snippet is invoked. Use F4 key to move from one field to the next.

Where are the code snippets located?

All code snippets are located in a single binary file. This file is located in the file system directory that serves as a common repository for application-specific data.

If you're running XP, the typical path is:
C:\Documents and Settings\username\Local Settings\Application Data\Adersoft\Vbsedit\snippets.dat

If you're running Windows Vista or later, it is:
C:\Users\username\Appdata\Local\Adersoft\Vbsedit\snippets.dat

If this file doesn't exist, the vbsedit_snippets.dat file located in the installation directory will be copied to the user directory.

To display the file path, Choose "Snippets" > "Organize Code Snippets...". The path will be displayed at the top of the window.

How to organize your code snippets?

Choose "Snippets" > "Organize Code Snippets..." to organize your code snippets.

You can click the "Export" button to export all your snippets to a folder on your hard drive. Vbsedit will create two files for each snippet. One will contain the source code for the snippet and one will contain the shortcut for the snippet.

You can click the "Import" button to import your snippets from a folder on your hard drive to your snippets file.

To automate these export/import features, you can run the following command lines:
 c:\program files\vbsedit.exe /importsnippets:myfolder
example:
c:\program files\vbsedit.exe /importsnippets:c:\mysnippets

c:\program files\vbsedit.exe /exportsnippets:myfolder
example:
c:\program files\vbsedit.exe /exportsnippets:c:\mysnippets


 Running scripts

Vbsedit enables you to run scripts from the command prompt (CScript) or from Windows (WScript).

Whether you use WScript or CScript, you still run the scripts in the same manner. The difference is only in the output — WScript generates windowed output, while CScript sends its output to the command window in which it is started.

To run scripts using CScript.exe

To run scripts using CScript, click [image] on the toolbar.

If you want to redirect output to Vbsedit output window, click [image] on the toolbar. If you redirect output to Vbsedit window, you still run the script with cscript.exe in the same manner. The difference is only in the output, CScript sends its output to Vbsedit output window.

What are the benefits of redirecting CScript ouput to Vbsedit output window ?

  • You don't have to switch from Vbsedit window to the command window while debugging.
  • Vbsedit automatically goes to the source line of the error when an error occurs while running
  • Vbsedit output window lets you copy the output to the clipboard.

To run a script with or without a logo

Select "options" in the tools menu. In the Debug tab, check or uncheck "Display logo when script executed in console mode".

To run scripts using WScript.exe

To run scripts using CScript, click [image] on the toolbar.

To automatically save the script before running

Select "options" in the tools menu. In the Debug tab, check or uncheck "Automatically save file before running".


 Using the Debugger

Your scripts may not always execute correctly the first time you build them. While some errors are easy to find and correct, others may be very difficult to locate. The debugger can help you track down and correct these errors.

Once you have opened the script you wish to debug, the debugger is invoked by choosing the "Start" button on the toolbar. You can also access debug commands from the Debug menu.

If you don't set any breakpoints, the execution will stop at the first line. When program execution is paused, a yellow arrow on the left of the screen points to the statement that will be executed next.

Here's the information you need to get started with debugging in Vbsedit :

  • Setting breakpoints
  • Stepping through scripts
  • Watching variables


 Settings arguments

Vbsedit enables you to supply arguments that will be passed to the script at run time.

When you start the script from within Vbsedit, it will pass these arguments to WScript/CScript as arguments for the script.

To set arguments, use the Arguments field in the toolbar.

Example

The following code samples display the entire set of command-line parameters associated with a script.

 Dim objArgs
Set objArgs = WScript.Arguments
For i = 0 to objArgs.Count - 1
  WScript.Echo objArgs(I)
Next


Setting breakpoints

 Setting and Using Breakpoints

Breakpoints allow you to pause program execution at a specific line of code while debugging a program. If a breakpoint has been set, choosing the debug command "Go" will cause the program to execute up to the breakpoint. To continue execution, choose one of the commands from the debug menu.

To set a breakpoint, position the cursor on the line where you want the program to break, then click the "Insert/Remove Breakpoints" button on the toolbar. The button contains a picture of a hand, and is usually located on the far right side of the toolbar. You can also set or remove breakpoints by pressing F9, the shortcut key for the "Insert/Remove Breakpoints" button. A red dot appears in left margin of the line on which the breakpoint is set.

To remove a breakpoint, use the same method. Clicking the "Insert/Remove Breakpoint" toolbar button (F9) will remove a breakpoint if there is one set one the line where the cursor is located. The red dot disappears when a breakpoint is removed.


 Stepping through scripts

Go The Go command executes code from the current location until it reaches a breakpoint, the end of the program, or a point at which the program pauses to get input from the user.

Step Into When Step Into is chosen, the debugger executes each statement one by one. Pausing to let the programmer check the values of variables or make adjustments between statements. Step Into lets the programmer step into every function call.

Step Out Step Out is used in conjunction with Step Into. It will immediately execute the remaining code in the current function call, then pause execution. The programmer can continue to debug the program.

Step Over This command is used to step through a program without stepping into function calls. When Step Over is used on a function call, the entire block is executed immediately.

When program execution is paused, a yellow arrow on the left of the screen points to the statement that will be executed next.


 Watching Variables

The appearance of the development environment will change when the debugger starts. The variables window is displayed on the bottom left of the screen. It allows the programmer to view the value of every variable relative to the current context of the program.

If a variable is an array, an object, or a structure, it will have a + or – tree control symbol beside it. By clicking on the symbol, you can view or hide its members.

How to change the value of a variable while debugging ?

Double-click in the value field

Modify the value and click OK

Tip

When you move the mouse over a variable name, a tooltip appears showing the variable value


 Convert Into Executable

VbsEdit lets you convert your scripts into standalone applications. Unlike the older versions of VbsEdit, the script will now be executed directly within the executable. The original script will no longer be extracted into a temporary folder.

Once converted, the source of your script will be nearly impossible to be viewed by other users.

Built-in WScript object

The application uses a built-in WScript object.

  • Create a new script with only one line: WScript.Echo WScript.ScriptFullname
  • Convert the script into an executable and run it. The ScriptFullname property is now the application's path!

    • UAC Execution Level

    VbsEdit adds an application manifest to the program that tells the operating system what the application needs. The possible requested execution level values are:

  • asInvoker: The application will run with the same permissions as the process that started it. The application can be elevated to a higher permission level by selecting Run as Administrator.
  • highestAvailable: The application will run with the highest permission level that it can. If the user who starts the application is a member of the Administrators group, this option is the same as requireAdministrator. If the highest available permission level is higher than the level of the opening process, the system will prompt for credentials.
  • requireAdministrator: The application will run with administrator permissions. The user who starts the application must be a member of the Administrators group. If the opening process is not running with administrative permissions, the system will prompt for credentials.

    • How does VbsEdit pre-populate fields and options?

    Let's say that you have a script named myscript.vbs that you have converted into myscript.exe. Now, you've made some modifications to myscript.vbs and you want to reflect the changes into myscript.exe.

    When you convert the script again, Vbsedit is able to load the options and fields from the existing myscript.exe to pre-populate the fields in the dialog box.

    If you want to load the options and fields from another application, set the application path to this other application and click the "Refresh" button.