'Can you debug VBScript in Visual Studio?
I was wondering if Visual Studio can run and debug VBScript files?
Thank you for your time.
Solution 1:[1]
First of all VBScript is an interpreted language and does not need to be compiled.
But yes, you can debug your VBScript file inside Visual Studio. Under "Tools / External Tools" you have to register the Windows Script Host (CScript.exe or WScript.exe) once with some startup parameters (to make it available in the Tools menu):
Title: VBScript Debug
Command: C:\Windows\System32\cscript.exe
Arguments: //nologo //X $(ItemPath)
Initial directory: $(ItemDir)
Check "Use Output window"
Hit the OK button
Then, just open the file you want to debug with Visual Studio (via File --> Open --> File...)
In order to start the debugger, just click "Tools / VBScript Debug".
The VS JIT debugger asks you, which debugger you want to use. Just select your *.vbs file and click Yes.
Note: This answer is still valid and works with Visual Studio 2019 & 2022.
Solution 2:[2]
For future readers.
This will work in a pinch.
"C:\Windows\System32\cscript.exe" /x MyFile.vbs
You will be prompted....and you can start a new instance of VS 2xxx (<< Whatever version is installed on your computer).
Not how to do it if you do it all the time..but good for every once in a while.
Solution 3:[3]
This worked for me when I wanted to debug slmgr.vbs script:
1) To enable the just in time debugger you have to enable it in the registry:
HKEY_CURRENT_USER\Software\Microsoft\Windows Script\Settings
set JITDebug=1
2) run command like this:
wscript.exe /x /d slmgr.vbs -xpr
3) The Visual Studio Just-In-Time debugger prompts for a possible debugger. You can just choose New instance of Microsoft Visual Studio 2012, click Yes button.
Solution 4:[4]
A debugger that i use is VBsEdit, (click here). It is free to use, and is helpful in getting to the route of a problem quickly, it also comes with a range of scripts that you can use. The one downside with the free version is that every program load will take one second longer than the last, unless you restart VBsEdit or buy the full version. Hope this helps
Solution 5:[5]
If you are interested by Visual Studio only to debug a VBScript, and nothing else, I recommend to install Visual Studio Community as it's free and install these minimum individual components so that to not occupy too much space (for VSC 2019 version 16.7.7, approximately "800MB" + "2.63 GB"):
- Compilers, build tools, and runtimes
- C++ CMake tools for Windows
- MSVC v142 - VS 2019 C++ x64/x86 build tools (v14.27)
- Debugging and testing
- Just-In-Time debugger
(NB: there could be other components automatically added, like "JSON editor") (NB: if you select only the JIT debugger, you'd get a popup error like "Unable to open script document. The debugger is not properly installed. Run setup to install or repair the debugger." and at the same time Visual Studio would display "Source not found" and "script.vbs not found")
After the installation, launch Visual Studio, make sure that the JIT debugger is activated for "Script" (menu Tools > Options > Debugging > Just-In-Time).
And then run the script using "C:\Windows\System32\cscript.exe" /x "My File.vbs"
in the two flavors as explained in the other answers, that will start the debugger.
If you want to see some screenshots of the installation and the debugging of the VBScript, go to this other Stack Overflow question/answer: https://stackoverflow.com/questions/59111755/how-to-debug-vbscript-with-visual-studio-community-2019
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Erik Anderson |
Solution 2 | granadaCoder |
Solution 3 | Angus Comber |
Solution 4 | AWS Cloud Architect Rob |
Solution 5 |