Debug the JavaScript/VB Script program (Wscript)

Source: Internet
Author: User

In the previous article "Debug JavaScript/VB Script program (IE)", the tutorial on helping customers (www.bkjia.com) introduced how to debug the Script program in IE. During routine operating system maintenance, we sometimes write some small script programs to simplify system management, such as calling some WMI functions to automatically install and uninstall programs.

In actual work, I found that the most complained about the script program by programmers is that it is difficult to debug the script program. Especially when debugging WSH programs such as. vbs, it is always:

1. Double-click a. vbs file in the resource manager.

2. An error occurs in the program, such as an exception or a programming logic error.

3. Read the source file in one row, and add Msgbox. Show to print the values of some variables in the estimated errors.

4. Run the. vbs file again.

5. "Dangdang", after a series of "OK" points are completed, people will also be dizzy and go back to Step 3 to continue ......

In fact, we can also use the Visual studiopilot wshprogram. The key is the interpreter wscript.exeand cscript.exe of the wshscript program, such as .vbs, which provides debugging support:

1. When we double-click a. vbs file in the resource manager, wscript.exe is run on the resource manager to explain and execute this. vbs file.

2. Both wscript.exeand cscript.exe support these two options/D-enable debugging and/X-execute the script program in the debugger.

In this way, we can use two methods to debug the script program in Visual Studio, here I will only introduce the second method -- the first method does not know why my Win 7 + Visual Studio 2008 cannot work ,:(.

For example, save the following. vbs code to c: "test. vbs. We want to debug this program. The source file is as follows:

Reference content is as follows:
Set obj = CreateObject ("System. Collections. ArrayList ")
Obj. Add ("this is a test ")
Obj. Add (1)
Obj. Add (obj)
Msgbox obj (0)
Msgbox obj (1)
Msgbox obj (2). ToString ()

1. Open the command line, change the directory to the C: disk, and execute the following command:

Wscript.exe/X test. vbs

2. At this time, a Visual Studio dialog box should pop up, prompting you to select a suitable debugger, just click the OK button above.

3. Finally, you can set a breakpoint in Visual Studio like debugging C # Or C ++ programs to view the value of the variable, as shown in:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.