Nathan Campos
Nathan Campos

Reputation: 29497

GUI Using Batch

When you try to do things using Windows Batch, you normally think on a Text Program, but I want to know if there is anyway to use instead of those string inputs at the command window, put on a TextField, and that the messages get displayed at a MsgBox. Also, if it's possible to hide the console window.

Don't matter if VBScript is needed, but only Batch should be better for me

Upvotes: 1

Views: 10752

Answers (6)

HighTechProgramming15
HighTechProgramming15

Reputation: 343

You can create a VBS-file using batch, execute that file and delete it when you are done:

@echo off

md temp
cd temp

(
echo Do
echo X=MsgBox^("This is an example of GUI using batch and VBS.",0+64,"Example"^)
echo X=MsgBox^("Do you want to exit this application?",4+32,"Exit"^)
echo If X=6 Then
echo Exit Do
echo End If
echo Loop
) > gui.vbs
gui.vbs

cd ..

(
echo dim filesys
echo set filesys = CreateObject^("Scripting.FileSystemObject"^)
echo filesys.DeleteFolder "temp"
) > delTemp.vbs
delTemp.vbs

del delTemp.vbs

Upvotes: 1

inovasyon
inovasyon

Reputation: 460

I tried to do this with just batch files but give up after a while. Instead, I'm quite happy with the solution I found. Check FroG which let's you to create nice looking and flexible GUI's just with XML. There are samples on their site to give you an idea. There is also a wizards apprentice (something like that) also XML based but it was rather limited. There are some more powerful alternatives out there but it looks like you don't want to involve complicated stuff. So I will not complicate the answer.

Upvotes: 0

Joey
Joey

Reputation: 354506

Without additional tools you're unlikely to succeed with batch files alone. VBScript makes displaying an input box or a message box trivial as you noted. From a batch file you can only show a message box and that one's not even pretty.

You can certainly hide the console window (ShowWindow will do that), but again, you'll need another program to do it for you. Also it's not nice to hide it if started from a shell already – let the batch file terminate prematurely and you have a console window hidden somewhere.

I'd suggest you use VBScript which runs on almost as many machines as pure batch files and is orders of magnitude better suited for what you want here.

Upvotes: 1

SiliconChaos
SiliconChaos

Reputation: 86

You might want to take a look at AutoIt, you are able to create executables (with no dependencies) which will not open a console window. You can create GUI windows or just popup plain input or message boxes.

Most of the automation programs/scripts I build are in AutoIt.

Upvotes: 1

EKS
EKS

Reputation: 5623

There was GUI programs in DOS, remember that all windows version before 98 SE all started from DOS ( Not NT kernal based os off course, like we are all using now).

Assuming your not planning on writing a DOS app ( qbasic can do this i think). You can off course do a few tings.

DOS based menus, sort of easy UI where you would use number on your keyboard to navigate. If your not going for any of the above solutions, you can use a batch file to Start a Windows applciation.

There are also solutions where you could either start a application, or even use a system compiler to compile the code for the app you want. You can off course start the DOS window hidden, that kind of depends on where you start it from.

Upvotes: 1

Patrick Cuff
Patrick Cuff

Reputation: 29786

I think the closest that you're going to get with just Windows batch is using the SET /P variable=[promptString] command to prompt the user for input.

I once worked in an area where there were a lot of batch scripts that needed lots of arguments passed to them, that the users (non-technical) found awkward and confusing (and justifiably so). I created a GUI "wrapper" for these scripts that would parse each batch file and create a dynamic GUI for its arguments. The user could click a button to run the script; I would shell out to an invisible console, capture the output, and display it in a scrollable textbox. The user could then copy the result to the clipboard or save it to a text file. Perhaps you can do something like that for your scripts?

Upvotes: 0

Related Questions