DOS and VBScript - A Better Interaction?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
Fawers
Posts: 187
Joined: 08 Apr 2012 17:11
Contact:

DOS and VBScript - A Better Interaction?

#1 Post by Fawers » 03 Jun 2012 09:56

Hello, all.

In this topic I'd like to talk about user interaction: making us of both .bat or .cmd files with .vbs scripts.
I'm thinking of some methods to make users interact with a Visual Basic Scripting message box or even with an input box within a batch file.
There are 2 (two) questions and 2 (two) answers for this:
• The first one is because interaction with VBS windows are much easier, specially if we're dealing with users that don't know much of DOS;
• The second one is, "why VBS within DOS? Why not only VBS?", well, I don't know how many of you do know WSH VBS, but I don't know too much of it. So the idea is to "import" some of its features into DOS.

I'm thinking of ways to prompt for user input using InputBox, show output (of any kind) with InputBox (so users can easily copy it), show messages with system icons using MsgBox (like those of "information", "question mark", "critical", and others.) and using MsgBox to make it work like "choice.exe", asking simple questions whose answers can and may only be "yes", "no", "cancel", "ok", "abort", "retry" and "ignore".

The ones who can code in VBS know what I'm referring to - VbYesNo, VbOkCancel, and others.


I'd like to know what your opinions on this are.

I'd also like you to know that one of the main reasons for me to think about this is because I know people that can't even know, they are supposed to press "Y" or "N" and {ENTER} in a SET /P statement.

Images
•Prompt for user input: http://img688.imageshack.us/img688/5606/inputd.png
•"Choice" prompt: http://img407.imageshack.us/img407/3298/choicevbs.png

Both of them will store input in a variable within DOS.

aGerman
Expert
Posts: 4654
Joined: 22 Jan 2010 18:01
Location: Germany

Re: DOS and VBScript - A Better Interaction?

#2 Post by aGerman » 03 Jun 2012 11:13

Well, it's an old new thing to combine Batch with other languages but it was never that popular.

In my opinion the interaction via keyboard is much faster than flailing with the mouse cursor. Interaction is not a matter for me to use it. Also it wastes a lot of time to call a VBScript.
There are other reasons why it sometimes may an option. Thinking of floating point calculations or DateTime support etc

Regards
aGerman

Fawers
Posts: 187
Joined: 08 Apr 2012 17:11
Contact:

Re: DOS and VBScript - A Better Interaction?

#3 Post by Fawers » 03 Jun 2012 11:50

aGerman wrote:Well, it's an old new thing to combine Batch with other languages but it was never that popular.

In my opinion the interaction via keyboard is much faster than flailing with the mouse cursor. Interaction is not a matter for me to use it. Also it wastes a lot of time to call a VBScript.
There are other reasons why it sometimes may an option. Thinking of floating point calculations or DateTime support etc

Regards
aGerman


I agree with you, keyboard interaction is way faster and easier than mouse, but I think this method would be easier for people who are not acquainted with the dos window. Perhaps I misused the words on my original post, but that was what I meant. Also, I think it's more readable as well.

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: DOS and VBScript - A Better Interaction?

#4 Post by Squashman » 03 Jun 2012 13:45

You might as well learn Powershell then.

Fawers
Posts: 187
Joined: 08 Apr 2012 17:11
Contact:

Re: DOS and VBScript - A Better Interaction?

#5 Post by Fawers » 03 Jun 2012 14:33

I've read somethings about Powershell, Squashman, and it looks very promising.
But I thought it was a console-like language. Does it have support for graphical interfaces?

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: DOS and VBScript - A Better Interaction?

#6 Post by foxidrive » 03 Jun 2012 17:47

I haven't had much to do with Powershell so I don't know either.

This is a routine I saved from a newsgroup long ago in 2004.

Code: Select all

@Echo Off
   :
   :
   Call :WshPopup "Do You Know The Expected Build Number?" 30 "Quick Question" 36
   :
   :
   Goto :EOF
  :WshPopup
:: SYNTAX:   Call :WshPopup Text Timeout Title Type
:: INPUT:
::   Text    Text to appear in the pop-up window
::   Timeout No. of seconds to wait before closing the pop-up window
::   Title   Text to appear in the title of the pop-up window
::   Type    Type of buttons and icons to display in the pop-up window,
::           combine this values:
::           0 = [OK]                        1 = [OK] [Cancel]
::           2 = [Abort] [Retry] [Ignore]    3 = [Yes] [No] [Cancel]
::           4 = [Yes] [No]                  5 = [Retry] [Cancel]
::           16 = Stop Mark                 32 = Question Mark
::           48 = Exclamation Mark          64 = Information Mark
:: OUTPUT:
::   Ret environment variable:
::           -1 = user did not click before 'Timeout' seconds
::            1 = [OK]       2 = [Cancel]   3 = [Abort]   4 = [Retry]
::            5 = [Ignore]   6 = [Yes]      7 = [No]

   Set Amp=&
   If %Amp%'==' Set Amp=^^^&
   Echo Set oSh = WScript.CreateObject("WScript.Shell")>%TEMP%.\_SHPOPU0.VBS
   Echo Ret = oSh.Popup(%1,%2,%3,%4)>>%TEMP%.\_SHPOPU0.VBS
   Echo WScript.Echo "Set Ret=" %Amp% Ret>>%TEMP%.\_SHPOPU0.VBS
::   pause
   CScript //Nologo //I %TEMP%.\_SHPOPU0.VBS > %TEMP%.\_SHPOPU0.BAT
   Call %TEMP%.\_SHPOPU0.BAT
echo Answer value is %ret%
   Del %TEMP%.\_SHPOPU0.*
   pause
   Goto :EOF


Fawers
Posts: 187
Joined: 08 Apr 2012 17:11
Contact:

Re: DOS and VBScript - A Better Interaction?

#7 Post by Fawers » 03 Jun 2012 18:07

The ones I wrote work in a similar way, foxidrive. The main difference is that I use a Wscript.ECHO to get any output.

Edit: links to the source-codes (in .txt files)
http://dl.dropbox.com/u/2332600/Scripts ... choice.txt - Choice
http://dl.dropbox.com/u/2332600/Scripts ... sinput.txt - Input
Last edited by Fawers on 05 Jun 2012 19:06, edited 1 time in total.

Fawers
Posts: 187
Joined: 08 Apr 2012 17:11
Contact:

Re: DOS and VBScript - A Better Interaction?

#8 Post by Fawers » 03 Jun 2012 18:16

And the other 2 links (forum allows only 2 URLs/post)
http://dl.dropbox.com/u/2332600/Scripts ... msgbox.txt - Standard MsgBox
http://dl.dropbox.com/u/2332600/Scripts ... output.txt - Output (using inputBox)

The reason I get the current code page and run CHCP 1252 is because I write my codes directly in OEM code page (which means, output would be only messed text if special characters exist)
Last edited by Fawers on 05 Jun 2012 19:06, edited 1 time in total.

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: DOS and VBScript - A Better Interaction?

#9 Post by Squashman » 04 Jun 2012 06:51

You pretty much have full access to the .NET Libraries.

Sapien Technologies used to have a Free Download of their Primal Tools that helped you make GUI for your PowerShell scripts. I used it for a while a few years ago just to learn the basics of what libraries I needed to use to make different interfaces. After a while I didn't needed it any longer because it was all upstairs.

Aacini
Expert
Posts: 1885
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: DOS and VBScript - A Better Interaction?

#10 Post by Aacini » 05 Jun 2012 01:23

Ok. This is what I think:

I don't think that a .vbs script (or PowerlShell script or anything like these ones) are good tools to be used in a .BAT or .CMD file script. The reasons to think that are simple:

- That "tools" are not directly executable applications. They all are interpreted solutions that require the loading of an interpreter to run. This means that they all are slow and, in many cases, they all are not suitable to fullfill the requirements of modern Batch file applications.

- I think the rigth way to provide Batch files with additional capabilites is via Win32 compliant .EXE executable files, in the same way than DOS/Windows provide additional capabilities to Batch files via FINDSTR or SORT .exe additional programs.

- I don't think that the use of Windows GUI functions be adequate to use in Batch files. We must remember that Batch files are reminiscent of old DOS Batch files in text mode. Otherwise, we may just forgive DOS commands/DOS Windows/Batch files and use "real" Windows applications that use mouse, and forgive "cmd line applications" that use text mode!!! In my opinion, any new Batch file application should be based in original DOS text mode.

As a matter of fact, I am writting right now a series of additional Batch commands in the form of .exe files that will provide Batch files with additional capabilities provided by the underlining Windows OS, but that will conform with the old DOS command-line text mode. I will post these new comands here very soon!

Antonio

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: DOS and VBScript - A Better Interaction?

#11 Post by foxidrive » 05 Jun 2012 02:02

Aacini wrote:I don't think that a .vbs script (or PowerlShell script or anything like these ones) are good tools to be used in a .BAT or .CMD file script.


I'm ok with them if they do the job, and in a reasonable time frame. Back in the MSDOS days we used Qbasic.exe to do things that just couldn't be done in batch, or was faster.
Even earlier than Qbasic there was GWbasic in MSdos.

As a matter of fact, I am writting right now a series of additional Batch commands in the form of .exe files that will provide Batch files with additional capabilities provided by the underlining Windows OS, but that will conform with the old DOS command-line text mode. I will post these new comands here very soon!

Antonio


That will be useful. I wonder if Dostips can host them, and then when solutions are written to use them then the OP can download the tools easily, and with confidence.

Squashman
Expert
Posts: 4465
Joined: 23 Dec 2011 13:59

Re: DOS and VBScript - A Better Interaction?

#12 Post by Squashman » 05 Jun 2012 05:36

I really wasn't referring to putting powershell inside a bat. I was more going along the route of just using pure powershell. They are building in some serious speed to Version 3 of PowerShell.

Fawers
Posts: 187
Joined: 08 Apr 2012 17:11
Contact:

Re: DOS and VBScript - A Better Interaction?

#13 Post by Fawers » 05 Jun 2012 12:13

@Squashman

I've done some quick reading on a few PowerShell tutorials, and it looks really interesting. I'll probably want to get more acquainted to it in the future. Right now I'm studying Python, and it also offers GUI support. Besides, it's cross-platform (which is very interesting). Anyway, all those "cmdlets" did grab my attention.

foxidrive wrote:
Aacini wrote:I don't think that a .vbs script (or PowerlShell script or anything like these ones) are good tools to be used in a .BAT or .CMD file script.


I'm ok with them if they do the job, and in a reasonable time frame.

Just as he said, if they do the job, it'll be interesting (at least for me). Besides, those I've posted contains only one line of code for each .vbs file, so it can't be "that" slow - unless we're talking about those 'super' slow machines. As an example, my machine is a WinXP SP3 from 2007; it does take some time to start, but everything else runs just smooth.

Aacini wrote:As a matter of fact, I am writting right now a series of additional Batch commands in the form of .exe files that will provide Batch files with additional capabilities provided by the underlining Windows OS, but that will conform with the old DOS command-line text mode. I will post these new comands here very soon!

This is very interesting! I would love to see and test them. By the way, how are you writing them as executables? Are you using a language like Ruby? I've heard somewhere it is able to make/build command line .EXEs.

Aacini
Expert
Posts: 1885
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: DOS and VBScript - A Better Interaction?

#14 Post by Aacini » 06 Jun 2012 22:02

Fawers wrote:...how are you writing them as executables? Are you using a language like Ruby? I've heard somewhere it is able to make/build command line .EXEs.

I only use the best: assembly language!

More than 25 years ago I wrote several small programs as auxiliary commands for Batch files. They were really small files, less than 400 bytes the majority. For example, below is my GetKey program that read a key from keyboard and return its Ascii code via ERRORLEVEL. This is the MS-DOS 16-bits version:

Code: Select all

mov   ah,8         ;DOS function: Keyboard input without echo
int   21H         ;AL = Ascii code of key pressed
mov   ah,4CH      ;DOS function: Terminate program
int   21H         ;Return Ascii code via ERRORLEVEL

This program generate a .COM file 8 (eight) bytes long! This program requires several modifications to make it Windows 32-bits compatible, so the resulting .EXE file is 1,536 bytes long! (although many of these are zero-filled bytes required in .EXE file format).

Antonio

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: DOS and VBScript - A Better Interaction?

#15 Post by foxidrive » 07 Jun 2012 01:26

Aacini wrote:More than 25 years ago I wrote several small programs as auxiliary commands for Batch files.
[snip]
This program generate a .COM file 8 (eight) bytes long! This program requires several modifications to make it Windows 32-bits compatible


Do you mean Win64 bit compatible? 32 bit Windows can run .com files.

As for 25 years ago ... I much prefer batch capability now that what we had back then. :)

Post Reply