Sign in to follow this  
Followers 0
whiplash

Batch bring up a popup??

8 posts in this topic

This is gona sound nooby - im sure this is possible but im not sure exactly how....

I want my batch file to bring up a windows box (for win xp pro if that makes a difference) -- one where you choose options (Ok or Cancel) - nothing special, just the grey box which gives you option buttons and the batch file will record the answer and use it to continue or leave out a certain section of the batch file

i dunno if ive explained it well enough but if you managed to understand wtf i just said, id appreciate some help on the matter lol

0

Share this post


Link to post
Share on other sites

If it could be done it would be very hard. I would recomend learning VBscript to do something like this.

0

Share this post


Link to post
Share on other sites
This is gona sound nooby - im sure this is possible but im not sure exactly how....

I want my batch file to bring up a windows box (for win xp pro if that makes a difference) -- one where you choose options (Ok or Cancel) - nothing special, just the grey box which gives you option buttons and the batch file will record the answer and use it to continue or leave out a certain section of the batch file

i dunno if ive explained it well enough but if you managed to understand wtf i just said, id appreciate some help on the matter lol

The most usefull stuff I managed to find on batch file programming is on this site, which covers some techniques to aquire user input too: Eric Helps

EDIT: actually, you'd probably be better off with this part of his site, the other bit was a bit dated. Have a look around anyway, might help.

Edited by coding_monkey
0

Share this post


Link to post
Share on other sites

A good idea is to use your batch file to open a vb script (this is where your gray box with the options to click on comes in)

and report back to your batch file...

I understand that this would be a little difficult to a beginner but, that would be the cleanest GUI form.

If your not looking for GUI just write the whole thing in batch and skip the gray box option, using basic if, and then functions.

Good Luck.

0

Share this post


Link to post
Share on other sites

ArpaNET, I second that. Another possibility is writing an EXE in Visual Studio and then just running that. DOS BAT has never been very flexible. It's damn near impossible to write something similar to 'echo -n' on UNIX (print a message without a newline), unless of course you want to do something like this :borg:

for %%v in (e100'%1' nCON rCX 400 w q) do echo %%v>>~tmp.bat

I got that from a post to alt.msdos.batch.nt.

0

Share this post


Link to post
Share on other sites

you could write it to open a file that will open the popup but i dont know

0

Share this post


Link to post
Share on other sites
A good idea is to use your batch file to open a vb script (this is where your gray box with the options to click on comes in)

and report back to your batch file...

I understand that this would be a little difficult to a beginner but, that would be the cleanest GUI form.

If your not looking for GUI just write the whole thing in batch and skip the gray box option, using basic if, and then functions.

Good Luck.

That's probably the way I'd do it, given that this was a windoze environment. You could do something 1337-er in your language of choice, but this is the two-cent beginning-coder solution that'll work in your flavour of windoze.

You'll need two files. The first is a batch file; for the purposes of this explanation we'll call it "asdf.bat". The batch file will use a CALL statement to execute the vbscript portion of your code. The vbscript is stored in the second file - we'll call it "asdf.vbs". The vbscript's job is to pop up a message box with a Yes/No question to answer. If the user clicks "Yes", the vbscript will pass a "1" to the batch file; if the user clicks "No" or closes out of the box, etc, it'll pass "0". Hopefully that makes some sense; here's the code part:

ASDF.BAT

CALL asdf.vbs
Echo %errorlevel%

Pretty simple, but we're not doing anything with the output once we have it. You might want to look into "IF" and conditional statements in batch files if you're planning on having your batch file do different things depending on what the user's clicked; let me know via PM if you run into any problems.

And here's what each line in the batch file does - in the hopes that it'll help somebody, even if it's pretty clear to you.

- "CALL asdf.vbs" makes your batch file look in the same directory it's running in for a file named "asdf.vbs". It executes that file and pipes any return code the file might quit with to an Environment Variable called "errorlevel". More on that in a moment.

- "Echo %errorlevel%" just prints the contents of the environment variable named "errorlevel" to the screen. In DOS and Batch Files, wrapping percent signs around a word tells the script to look through the environment variables until it finds one with the name between the percent signs. In very basic terms - environment variables are programming settings that your operating system keeps track of.

So: CALL tells the batch file to execute our VBScript, and then ECHO prints whatever the script quit with to the screen. Easy day!

ASDF.VBS

Dim ReturnVal
ReturnVal=Msgbox("Is This A Yes/No Question?",VBYesNo,"EnterSomeTitleTextHere")
If (ReturnVal=6) Then
WScript.Quit 1
Else
WScript.Quit 0
End If

This is a bit trickier, but really not any harder to understand. Again, send me a PM if you need more data on something in here, or help modifying it to your specific needs.

And let's go line-by-line to describe what's happening, just in case some poor n00b finds this post off of google:

- "Dim ReturnVal" declares a new variable named "ReturnVal". This is what we'll use to store whether or not the user clicked "Yes" or "No".

- "ReturnVal = MsgBox(...)" is a long and potentially intimidating line, but pretty self-explanatory once it's broken down. In this line, our trusty variable "ReturnVal" is going to take whatever the user clicks in VB's built-in Pop-Up-MessageBox and store it there. "MsgBox()" is a function that's built into VBScript; it tells windows to open a pop-up window. But a plain pop-up window with an "OK" button in it won't really help us for what you're trying to do, so we feed the function three parameters, separated by commas. The first one reads "Is This A Yes/No Question?" - it's the text that appears inside the pop-up window, right above the buttons. The second one reads "VBYesNo" - this tells the window what buttons to put on the pop-up window. (You can find a full list of types here). The third one reads "EnterSomeTitleTextHere" - this is the text that appears in the title bar of the pop-up window - the bar at the top, to the left of the minimize, maximize, and close buttons.

- "If ReturnVal=6" is a Conditional Statement that checks to see if our "ReturnVal" variable is the number "6" - which means the user clicked the "Yes" button. (If they clicked the "No" button, "ReturnVal" would be the number "7" - I'm not sure why either). If so, the script executes the line immediately below it (WScript.Quit 1) - otherwise, it executes the line under the line that reads "Else" (WScript.Quit 0).

- "WScript.Quit 1" tells the script that it should quit, and set the %errorlevel% environment variable to "1". Pretty straight-forward! I'll skip the "Else" and the second "WScript.Quit" to avoid being redundant, which brings us to:

- "End If" - VBScript needs this to know where the Conditional Statement ends. Pretty boring. :-/.

So - that's the exhaustive post on how to do what ArpaNet was talking about; sorry for the length - and let me know if you run into any problems with the code.

-ArchAngel

Edited by Angel
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0