Using VBScript To Control A MS-DOS Program

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
SmokingNumbers
Posts: 1
Joined: 20 Jun 2014 12:10

Using VBScript To Control A MS-DOS Program

#1 Post by SmokingNumbers » 20 Jun 2014 12:13

Using a VBScript (just an example) something like

Code: Select all

result = MsgBox ("Would you like to install the AntrixAPI?", vbYesNo, "Installing AntrixAPI")

Select Case result
Case vbYes
MsgBox("The API will be installed.")
Case vbNo
MsgBox("The API will not be install.")
End Select


How could I use this to control a MS-DOS program. Let's say the user selected yes. Then the MS-DOS command would go to a certain point only if the user selected yes. (example ms-dos command)

Code: Select all

@echo off
:UserSelectedYes
REM This is where the prompt would go if the user selected yes
wget http://www.example.com/thisisafakedomain/api/antrix
:UserSelectedNo
REM This is where the prompt would go if the user selected no
end


Would this be possible?

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Using VBScript To Control A MS-DOS Program

#2 Post by Ed Dyreen » 20 Jun 2014 19:46

Windows Script Host
Run Method (Windows Script Host)

Runs a program in a new process.
object.Run(strCommand, [intWindowStyle], [bWaitOnReturn])

The following VBScript code opens a copy of the currently running script with Notepad.

Code: Select all

Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "%windir%\notepad " & WScript.ScriptFullName
The following VBScript code does the same thing, except it specifies the window type, waits for Notepad to be shut down by the user, and saves the error code returned from Notepad when it is shut down.

Code: Select all

Set WshShell = WScript.CreateObject("WScript.Shell")
Return = WshShell.Run("notepad " & WScript.ScriptFullName, 1, true)
The following VBScript code opens a command window, changes to the path to C:\ , and executes the DIR command.

Code: Select all

Dim oShell
Set oShell = WScript.CreateObject ("WSCript.shell")
oShell.run "cmd /K CD C:\ & Dir"
Set oShell = Nothing


Windows Script Host
Exec Method (Windows Script Host)

Runs an application in a child command-shell, providing access to the StdIn/StdOut/StdErr streams.
object.Exec(strCommand)

The following example demonstrates the basics of the Exec method.

Code: Select all

Dim WshShell, oExec
Set WshShell = CreateObject("WScript.Shell")

Set oExec = WshShell.Exec("calc")

Do While oExec.Status = 0
     WScript.Sleep 100
Loop

WScript.Echo oExec.Status
Learning vbScript/jScript is difficult without the proper tools to aid you in your quest.
try this free program http://www.vbsEdit.COM

Post Reply