Blog of the Bao-‘dad’ Tree

Reaching out   –   Giving back   –   Looking inward   –   Paying forward 
« Back to blog

Step-through VBscript Debugging

First of all, let me say at the outset that if there is any way at all you can use Windows Powershell instead of VBscript, do it.  Powershell is the future of Windows scripting.

But we all have to go back and fix things from the past sometimes, and when we do it's nice to have some tools.

One of the great tools I use is Notepad++, a free and highly configurable text editor for Windows.

You can configure Notepad++ to open up a debugging program to step through the file you've currently got open.  First you have to edit your %APPDATA%\Notepad++\shortcuts.xml file.  In the <UserDefinedCommands> element, add this line:

<Command name="Debug VBscript" Ctrl="no" Alt="no" Shift="no" Key="0">wscript.exe //D //X &quot;$(FULL_CURRENT_PATH)&quot;</Command>

This will add a command to the Notepad++ "Run" menu, that will execute the currently saved version of your open file with wscript.exe, with the //D switch to tell it to debug if it encounters any errors, and the //X switch to immeditely throw an error at the beginning of execution.

Next, what debugger should you use?  Often you can get Microsoft Script Debugger to come up, but if it all possible, see if you can use Microsoft Script Editor.  Microsoft Script Editor comes with Microsoft Office; I can find mine in %PROGRAMFILES%\Microsoft Office\OFFICE11.  It's called MSE7.EXE.

It took a little doing to figure out how to get it to come up as a debugger.  I think this registry edit should do the trick.  Create a .reg file with these contents and merge it with your registry [Disclaimer: DO ONLY AT YOUR OWN RISK!  Making a mistake modifying the registry can crash your computer]:

REGEDIT4

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Machine Debug Manager\JITDebugging\Engines\{F200A7E7-DEA5-11D0-B854-00A0244A1DE2}]
@="Script Only"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Machine Debug Manager\JITDebugging\Engines\{F200A7E7-DEA5-11D0-B854-00A0244A1DE2}\{000C1227-0000-0000-C000-000000000046}]
@=""
"Remote"=dword:00000001

For more help check here:
http://support.microsoft.com/kb/308364

Comments (2)

Aug 13, 2009
Luke said...
Thanks for these. Very useful. Do you know how to attach to IIS for classic ASP in vbscript?
Aug 14, 2009
Baodad said...
Sorry, No.
Once I had to make some edits to an ASP-based application, and I googled and googled to try to find something (free) to help me step-through debug them. My problem was that the ASP was running on the server, and like you said, you have to attach to it somehow.

Leave a comment...

 
Got an account with one of these? Login here, or just enter your comment below.
Posterous-login    Connect    twitter