Register now to gain access to all of our features. Once registered and logged in, you will be able to create topics, post replies to existing threads, give reputation to your fellow members, get your own private messenger, post status updates, manage your profile and so much more. This message will be removed once you have signed in.Login to AccountCreate an Account

Javascript Disabled Detected

You currently have javascript disabled. Several functions may not work. Please re-enable javascript to access full functionality.

[VBScript] MsgBox with auto select countdown and Batch Script input.

Outbreaker

Posted 15 October 2009 - 03:27 AM

Outbreaker

Advanced Member

Member

307 posts

Joined 08-August 07

OS:Windows 7 x86

Country:

HI

I need help to make a VBScript that i can call with a Batch Script file and schould show then a MsgBox with a Yes/No option and a 30 seconds countdown. If a user has not selected a option and the time is up then the VBScript should automatically select the option Yes and also go to the Batch Script line XY1 and if No is selected then it should go to the Batch Script line XY2.

I google for over 3 hours but i could finde only a simple Yes/No MsgBox VBScript and only one that had also a countdown option but this script was bugy and had also not the Batch Script GoTo line XY option.

This assumes both files are located in the same directory.
Change the text you want displayed to the user.
The vb script uses the quit method of wscript to provide an exit code that the batch
file can use with an errorlevel check to determine what was chosen.

Another way to do this would be a HTA, this HTA will close in 30 seconds and show the yes diplay text before closing.There are 2 buttons a Yes and a No button press either one to see how the script works.

Outbreaker

Posted 15 October 2009 - 12:48 PM

Outbreaker

Advanced Member

Member

307 posts

Joined 08-August 07

OS:Windows 7 x86

Country:

Nice MsgBox popup never heard about this HTA before.
But would this also work with the Batch file like with the VBScript ?
Like if the DemoMsgBox.hta is started by the Batch file and the option Yes is selected then got to Batch Script line XY1 and if the option No is selected then go to Batch Script line XY2.

If this would works this would be the best Yes/No prompt Script for a Batch file.

gunsmokingman

Posted 15 October 2009 - 02:10 PM

gunsmokingman

MSFN Master

Super Moderator

2,447 posts

Joined 02-August 03

OS:none specified

Country:

You would not need to have any batch files around, you could run the cmd directly from the HTA either yes or no button.
Could you post the cmds you need to run for yes and no button reply, I will add them to the HTA for you.

Outbreaker

Posted 15 October 2009 - 02:41 PM

Outbreaker

Advanced Member

Member

307 posts

Joined 08-August 07

OS:Windows 7 x86

Country:

Oh to put the batch script in the HTA file would be not so good it's a big Batch file and i have also separat all Script languag for each other like that it is not so confusion because the whole Scripts config files that i use to configure Windows are like 200KB together.
If this is not working like in the VBScript then i could also make 2 more Batch files so if Yes is then selected it will Start the Batch file XY1 and if No it will Start the Batch file XY2.

Yzöwl

Posted 16 October 2009 - 07:15 AM

I'd suggest you take a look at a GUI scripting tool such as AutoIt for this task.

In the meantime I suppose I could take a shot at creating a YES | NO box with 30 second countdown specifically for this task. You'd probably end up running it as an executable from the batch and have it return the result back to the batch. It'd be no real use for anything else hence my reason for not doing so unless it's required.

Also if it is required, then you'll need to let me know exactly what data you'd want it to return.i.e. I was thinking 1 for YES, 2 for NO; meaning that your batch could probably use the return data as:GOTO XY<RETURNED DATA>

Outbreaker

Posted 16 October 2009 - 12:22 PM

I like the idee to use Scripts that i can open with the text edtor and edit it without a program if the next step will not work then AutoIt would be the only way.

So it looks like the HTA could not be used like the VBScript to output a command to the Batch file.
But what if i would select Yes and the HTA Script would make a Batch file in the Temp folder with the text "Yes" in it and then the main Batch file would then call the Batch file in the Temp folder and look if "Yes" or "No" is written in it and if like "Yes" is written in then the main Batch file gose to the line XY1 and if "No" is written it will go to the Batch line XY2.

gunsmokingman

Posted 16 October 2009 - 06:57 PM

Rigatoni

Posted 31 August 2011 - 09:03 AM

Rigatoni

Member

1 posts

Joined 31-August 11

OS:Windows 7 x64

Country:

I am trying to do a simular job and i like what you have put together. I have one request if you are able to help it would be appreciated. Thanks
Is it possible for the cmd to read the results of the hta and if reply = yes lauch a specific .cmd (lets say c:\test.cmd) and if reply = no do nothing.

DefaultScript

Posted 31 December 2011 - 08:18 PM

DefaultScript

Member

2 posts

Joined 31-December 11

OS:Vista Ultimate x86

Country:

Gunsmokingman, Thank You immensley for this script as it has done almost everything i needed....However (of course lol) i am having trouble with the location of the output file... i need it to be generated within the script folder that is calling it... i have tried changing line 65 location from %temp% to

Dim Cmd :Cmd = Act.ExpandEnvironmentStrings("%cd%") & "\BannerResult.cmd"it errors and states "PATH NOT FOUND"however when i use ...Dim Cmd :Cmd = Act.ExpandEnvironmentStrings("%userprofile%\desktop") & "\BannerResult.cmd" it runs fine however it puts the file to the users desktop then i have another script that deletes the generated file once it reads the reply answer. what am i missing with getting it to generate within the called script folder.

Any takers on this question, i would be forever greatful. been smacking my head on the table for days trying to figure it out, i must have reloded this script about 500 times.... lol Great Script though overall

thanks in advance for anyone that is looking it over. attached below is the window script modified from what Gunsmoking man originally wrote.

Also i changed it so the script closes automatically at the timer "0" generating no file. Only Generates output file if yes button is clicked.

This is the (Edited for Public) Check Banner Result Script (Batch File)

Thanks very much.... after looking at what you had above i figured it out lol. i did try the Act.CurrentDirectory however it wasn't generating the output to the folder. it was actually placing the output in the next higher folder and renaming the file appending the lower directory name as a prefix on the filename, hence not being able to find it caus it no longer carried the requested filename.

this was all because of the darn \ before the filename. in my code i had not put the \ before the filename and same with using your original script , i needed to remove the env variable.

now....i have read more on this act.currentdirectory and feel a bit more "trained" lol, thanks again oh and also my original script was fine as well once i removed the \ and just placed the filename itself in the line as such

use this as the output into same directory as calling scripts... Just Remove the ("%userprofile%\desktop") & from the line....

bphlpt

Posted 01 January 2012 - 01:20 PM

bphlpt

MSFN Addict

Member

1,914 posts

Joined 12-May 07

OS:none specified

Country:

Sorry for the noob questions, but...

I've never played with HTA files before so I'm confused how they are used/called. I put DefaultScript's Check Banner Result Script (Batch File) [named CheckBannerResult.cmd] and the Banner Script (HTA File) [named BannerScript.hta], with the fix from the last post, in their own folder with nothing else in there. Now what? being a noob I have no idea how to invoke the hta and get it to "work". I like this concept, if I understand it, but I'm afraid I'm very confused. Maybe someone can point me to a "HTA files for Dummies" tutorial?

Geej

Posted 03 January 2012 - 07:46 PM

Geej

Senior Member

Member

635 posts

Joined 01-January 08

OS:XP Pro x86

Country:

A happy 2012 new year to all coders here!

Thanks to gunsmokingman's HTA script which inspire me to try to code in autoit.I was very interested to see what code would be like if using autoit and also to experience'GUI scripting' as Yzöwl mentioned earlier as I am not familiar with it. So I try to script it using autoit.Took me days to come up the script... and 2 parts of the script were extracted from the autoit forum.They are1) Create only "Close" buton on the main GUI Source2) Timer countdown logic SourceWith that, autoit code which mimic what HTA script doesCode with autoit v3.3.6.1. Also works with v3.3.8.0Note that the timer will beep on last 10 secs countdownTimer font also changed during this period.