How to comfortably monitor variables in a VBscript during development process? (e.g. in a continuously opened command window) - vbscript

I need to write a huge VBscript to automatically run an application and I'm looking for a way to comfortably monitor what I'm actually doing, in other words, to display the values of some/all variables involved in my script.
I'm used to work with Matlab, where I have a comfortable workspace browser. When I run a Matlab script, all variables, their types and their values are accessible in that workspace and can be checked.
The VBscript I write with Notepad++ (it needs to be a free editor) and the only way I found to display variables was echoing them via wscript and cscript.
I set up the shortcuts.xml with the following line to run my script directly from Notepad++:
<Command name="Run with CScript" Ctrl="yes" Alt="no" Shift="yes" Key="116">cmd /K %windir%\system32\cscript.exe "$(FULL_CURRENT_PATH)"</Command>
In case I include commands in my script like
Wscript.Echo myVar
Wscript.Echo "Hello World!"
and run it with the newly introduced shortcut, a cmd window pops up and displays the value of myVar and "Hello World!".
But the next time I run the script a new window pops up. So my question is:
Is it possible get a continuously opened output window, displaying all echoed values everytime I run a script? I actually want to put the window on a second screen and keep the values from previous runs. So I can enter a line Wscript.Echo something, run, check, enter something else and so on, without fiddling around with a bunch of opened windows.
Alternatively, is there any open-source/free editor which offers an accessible workspace like the one in Matlab?

The open-source editor SciTE offers what I was looking for.
The default settings in vb.properties enable a similar behavior like in Notepad++
command.build.$(file.patterns.wscript)=cscript "$(FilePath)"
command.build.subsystem.$(file.patterns.wscript)=1
One can change it as follows to get the output into the integrated console.
command.go.$(file.patterns.wscript)=cscript.exe //nologo "$(FilePath)"
command.go.subsystem.$(file.patterns.wscript)=0
F5 runs the script and Shift+F5 cleans the output.
Another option is the NppExec Plugin for Notepad++ suggested by #Ansgar Wiechers, which adds a console. The script can be run with cscript.exe /nologo "$(FULL_CURRENT_PATH)" then.

Use a debugger. Start your script with the (meta)option //X. If you are lucky, you already have installed software (MS Office, Visual Studio (Express)) that provides a debugger for VBScript. If not do a bit of research to find an Express version suitable to your OS.

You can almost write native VBScript in the VBA editor, so if you have Excel or whatever you can use this to debug, then go through some steps to convert back to VBScript. That's what I usually do.

Related

Alternative to cmd and powershell for stdout output only

My use case:
I kick-off a Python script from a button within Excel to do some data aggregation. The setup currently works nicely, but I would like:
Cmd to never accidentally pause - it's a known feature of the command prompt to pause on any text selection: Avoid pausing tasks when select something on PowerShell and Command Prompt
To let the cmd prompt look more like a pop-up
I have noticed NSIS installers outputs it's commands in a little logging box:
Question:
I would like to know if there are any programs out there that does most of what I want already. E.g. something like RunLikePopup.exe c:\path\to\script.bat, with output like:
Not sure what you are really after. I 'll give it a try.
In case you build an application as 'console'-only than that results in a 'command-line-interface [CLI]' Look-and-feel. Plane and simple. The output of a NSIS script (.nsi file) can not be paused as it is simply the output of the compiler executing the script code. 'Pausing' that would instantly mean pausing the compiler to do its work. I see no reason why you would want that.
Example Unix 'more' command (sending text oriented content to stdout. CLI...)
https://en.wikipedia.org/wiki/More_(command)
In case you need to 'catch' the output from the NSIS compiler here is what you need to do:
run NSIS from (Windows) CLI:
makensis [ option | script.nsi | - ] [...] > compiler_log.txt
What you appear to want is typically named 'output redirect'. (https://ss64.com/nt/syntax-redirection.html). In case you need to 'catch' the outpout from a NSIS script at compile time, please use NSIS ' CLI and redirect the (compilers) output to any text file (e.g. compiler_output.txt)
PS. In order to ensure receiving good quality answers, try to be as specific as you can in your questions.
I have written a Freeware editor ME "Martins Editor" where you can send text via inpipe:
[C:\]dir /s | me in
"in" always shows the first page (does not scroll), "ins" scrolls and "inp" scrolls page by page. In this context, "me in" is a substitute for "more".
Then you will see the output in the editor. ME is a simple editor with the focus on multiplatform text (different EOL encodings, codepages). It has additional Wordstar ("IDE classic") key setting and HTML/XML highlightning. It is available for Windows, OS/2, Linux and MacOS.
http://www.hypermake.com/english/betatest.html#hd117
The 2016 version is still current. In the next weeks, I publish a new version.
I am working on a cmd.exe window replacement (commandline frontend) "MeShell" based on ME with look-and-feel of a normal commandline window. Because on the lack of a modern comfortable commandline window on the old OS/2 platform which is still alive (http://www.arcanoae.com), I will publish an OS/2 version first. If this version works fine, I will publish a Windows version later. In the context of MeShell, I improve the inpipe functionality of ME which is still buggy and does not support colors in the 2016 version.

How to Launch a Metro App from Microsoft Access VBA on Windows 10 Computer

I have a situation in which I wanted to utilize the camera app in Windows 10 from my Microsoft Access program. Normally I could just send a command to execute the program's executable, but with the metro app there is no straightforward executable.
The basic code I use is this:
Shell """" & PthToExe & """", vbNormalFocus
PthToExe is the path name for the executable.
I looked around a decent bit, but was unable to find any simple solutions and ended up coming up with my own. My solution is to make a shortcut link to the camera application and then to launch the link.
In order to make a shortcut link in Windows 10, you can click on the start button, go to "All Apps", find the app you want (in my case "Camera"), and then click and drag it to the desktop.
Now that you have a shortcut, you can launch the shortcut from a command line. (So my shortcut doesn't clutter up my desktop, I dragged it off my desktop and into a folder on the "C" drive.)
Type the path into a command prompt like this and hit enter to test launching your app: C:\GJ\Camera.lnk
So that solves the problem if you wanted to launch from a command line. For some reason, though, Access would not accept that command. The way I got around it was I put the command in a batch file (Edit: Alternatively, see HansUp's comment). To do that, you just need to open notepad, type in the same thing you typed in the command prompt, save the note pad document, and then rename the document to have a .bat extension.
You can then execute the .bat file from Microsoft Access as follows:
Shell "C:\GJ\OpenCamera.bat", vbMinimizedNoFocus
Note that normally, I use vbNormalFocus when running the shell command, but in this case, it is desirable not to see the little command prompt open before the actual program opens.

Windows Batch: Running a Ruby program opens a cmd window

I basically would like to execute a (Cygwin-) Ruby program by clicking on some icon on my desktop. My first attempt went like this:
Create a desktop link
As a link target, have something like
c:\cygwin64\bin\ruby /path/to/my/ruby/program
This works, but it also opens a window where Ruby "runs in", which is not what I want to have.
If it were ActiveState Perl, I would have a command "wperl", which executes Perl without creating a Window, but such an feature doesn't seem to exist for Ruby, at least not for the Cygwin distribution.
I tried to change the link to
cmd /MIN /C c:\cygwin64\bin\ruby /path/to/my/ruby/program
hoping, that this would run the window minimized, but same effect as before, so I think I need to program somehow a wrapper script which suppresses the creation of this window. Does anybody know how this can be done, preferably using the Windows Batch language or some clever commands in the Cygwin tool chain?

Trying to run .vbs as a startup program. Forcing to run in cscript. Want it to run in background, instead of having a script host window open

So I've done some digging to try and find a way to run a script in the background on startup. The only solution I've found is to use:
Set WinScriptHost = Nothing
Is this a reasonable way to do it? Or could it cause some issues? I mean, from what I can tell, it just stops WinScriptHost from being used to refer to an object. But I feel like that could cause trouble in some scripts. So, should I avoid using this method and do something else?
Thanks!
CScript is for console windows, consoles programs by their definitions have a console. WScript is for GUI programs, unlike console programs, windows are optional (although almost all programs will create a hidden main window if not creating a visible window, as windows are how Windows communicates with a program).
Using WshShell.Run, which has a window style parameter, you can run cmd hidden eg cmd /c cscript script.vbs.

how to hide cmd from appearing at the back of your .vbs application?

I am new to building apps using simple .vbs coding, whenever I build a .exe file using visual basic script command prompt opens along with the application at the background. so how to hide the command prompt from appearing??
and also how to set a background image in a pop up or input box?
To your first question, it depends on how you are calling the vbs. Windows allow to execute tasks with hidden windows. If you can not create a hidden window and you doesn't need the console, instead of using cscript as the executable for the vbs, use wscript.
Popup and input box from vbscript are standard elements of the system. AFAIK no way of change background of them.

Resources