At work I needed to cook up some VBScript to manipulate text files, and copying to another file/folder. I wanted to verify my script will run (ie. no syntax or script errors) before I turn it in.
A good tool for debugging VBScript is using CScript. SeeĀ https://technet.microsoft.com/en-us/library/bb490887.aspx to read more about it.
You can access CScript by going to command prompt. Here I’d cd to the script directory where I want to run/debug my script:
C:\temp\vbscripts>cscript
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.Usage: CScript scriptname.extension [option…] [arguments…]
Options:
//B Batch mode: Suppresses script errors and prompts from displaying
//D Enable Active Debugging
//E:engine Use engine for executing script
//H:CScript Changes the default script host to CScript.exe
//H:WScript Changes the default script host to WScript.exe (default)
//I Interactive mode (default, opposite of //B)
//Job:xxxx Execute a WSF job
//Logo Display logo (default)
//Nologo Prevent logo display: No banner will be shown at execution time
//S Save current command line options for this user
//T:nn Time out in seconds: Maximum time a script is permitted to run
//X Execute script in debugger
//U Use Unicode for redirected I/O from the console
Usage is very simple, you simple type cscript yourscript.vb at the command prompt to run your script.
An example error I’ve came across when dealing with deleting a file is:
C:\temp\vbscripts\myscript.vbs (36, 1) Microsoft VBScript runtime error: Permission denied
The (36, 1) tells you the error occurred on line 36. Now go figure it out what’s wrong with it.