Click here to Skip to main content
14,386,126 members

How to Debug Visual Basic Script with Visual Studio

Rate this:
3.73 (14 votes)
Please Sign up or sign in to vote.
3.73 (14 votes)
29 Nov 2019CPOL
This tip shows how easy it is to debug the VBScript by using Visual Studio Debugger

Introduction

If you are programming with Visual Basic Script, you have difficulties to find a bug in your script: there isn't any debugger for VBS! This tip shows how you can easily use Visual Studio for this.

Background

Normally, you start a script from the command line like this:

Quote:

cscript.exe myScript.vbs

In order to debug your script you only need to add the parameter /x:

Quote:

cscript.exe /x myScript.vbs

This will set a breakpoint and throw an immediate exception, which starts the debugger immediately after the script starts running.

The following dialog will be shown where you can choose Visual Studio and step into your VBS code:

Image 1

Not all versions of Visual Studio support Just-In-Time debugging, especially the VS Express Editions are the problem. You recognize whether your version supports the JIT debugging as follows:

Quote:

Visual Studio -> Tools -> Options -> Debugging -> Just-In-Time

Image 2

A good news: the new Visual Studio 2019 (even the Community Edition) do support the VBS debugging!

Useful Links and Information

  1. Creating And Using Scripts - http://wsh2.uw.hu/ch01d.html#20
  2. How To Debug WSH, VBScript And JScript

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

_duDE
Software Developer
Germany Germany

I'm a software developer living in Germany with my family (wife & 2 sons).
My hobbies: sport, traveling, books (former reading, now hearing).
Welcome to my homepage: http://leochapiro.de

Comments and Discussions

 
GeneralMy vote of 5 Pin
Gustav Brock3-Dec-19 2:22
professionalGustav Brock3-Dec-19 2:22 
GeneralRe: My vote of 5 Pin
_duDE4-Dec-19 0:42
professional_duDE4-Dec-19 0:42 
QuestionVery helpful, thank you! Pin
SmokeHead29-Nov-19 10:49
MemberSmokeHead29-Nov-19 10:49 
AnswerRe: Very helpful, thank you! Pin
_duDE29-Nov-19 10:51
professional_duDE29-Nov-19 10:51 
PraiseMessage Closed Pin
29-Nov-19 9:58
MemberMember 1467299129-Nov-19 9:58 
QuestionPossible typo Pin
Member 460889821-Jan-17 22:13
MemberMember 460889821-Jan-17 22:13 
AnswerRe: Possible typo Pin
_duDE23-Jan-17 6:13
professional_duDE23-Jan-17 6:13 
GeneralMy vote of 1 Pin
Abhishek Kumar Goswami17-Sep-15 6:43
professionalAbhishek Kumar Goswami17-Sep-15 6:43 
GeneralRe: My vote of 1 Pin
_duDE17-Sep-15 20:39
professional_duDE17-Sep-15 20:39 
GeneralRe: My vote of 1 Pin
SmokeHead17-Sep-15 23:03
MemberSmokeHead17-Sep-15 23:03 
Questionproposals to update your useful article Pin
Emmet M13-Jan-15 8:03
MemberEmmet M13-Jan-15 8:03 
AnswerRe: proposals to update your useful article Pin
_duDE13-Jan-15 8:41
professional_duDE13-Jan-15 8:41 
AnswerRe: proposals to update your useful article Pin
Member 334412913-Jan-15 14:06
MemberMember 334412913-Jan-15 14:06 
GeneralRe: proposals to update your useful article Pin
_duDE13-Jan-15 19:48
professional_duDE13-Jan-15 19:48 
Questionuseful tip Pin
Member 334412913-Jan-15 4:33
MemberMember 334412913-Jan-15 4:33 
AnswerRe: useful tip Pin
Nelek13-Jan-15 5:12
protectorNelek13-Jan-15 5:12 
GeneralMessage Closed Pin
13-Jan-15 8:42
professional_duDE13-Jan-15 8:42 
GeneralRe: useful tip Pin
Nelek13-Jan-15 11:31
protectorNelek13-Jan-15 11:31 
GeneralRe: useful tip Pin
Member 334412913-Jan-15 14:04
MemberMember 334412913-Jan-15 14:04 
GeneralRe: useful tip Pin
Nelek13-Jan-15 15:09
protectorNelek13-Jan-15 15:09 
GeneralRe: useful tip Pin
Member 334412914-Jan-15 7:43
MemberMember 334412914-Jan-15 7:43 
AnswerNot a tip Pin
Akhil Mittal 13-Jan-15 2:11
mva Akhil Mittal 13-Jan-15 2:11 
GeneralRe: Not a tip Pin
_duDE13-Jan-15 2:51
professional_duDE13-Jan-15 2:51 
GeneralRe: Not a tip Pin
Abhishek Kumar Goswami17-Sep-15 20:58
professionalAbhishek Kumar Goswami17-Sep-15 20:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Tip/Trick
Posted 12 Jan 2015

Stats

91K views
20 bookmarked