Jump to content

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


Recommended Posts

Change This

Dim Cmd :Cmd = Act.ExpandEnvironmentStrings("%userprofile%\desktop") & "\BannerResult.cmd" 

To this to get the output in the Current Directory

Dim Cmd :Cmd = Act.CurrentDirectory & "\BannerResult.cmd" 

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. :sneaky: 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. :sneaky:

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. :ph34r:

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....


Dim Cmd :Cmd = Act.ExpandEnvironmentStrings ("BannerResult.cmd")

that created the file in the same folder as the called script.

Link to comment
Share on other sites


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?

Cheers and Regards

Link to comment
Share on other sites

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 are

1) Create only "Close" buton on the main GUI Source

2) Timer countdown logic Source

With that, autoit code which mimic what HTA script does

Code with autoit v3.3.6.1. Also works with v3.3.8.0

Note that the timer will beep on last 10 secs countdown

Timer font also changed during this period.

opt("TrayIconDebug",1)
Opt("MustDeclareVars", 1)
Opt("GUIOnEventMode", 1);1=enable, Enable/disable OnEvent functions notifications.
Opt("GUICoordMode", 1) ;1=absolute, 0=relative, 2=cell
#NoTrayIcon ; No system tray icon while running

#include <WindowsConstants.au3> ; $GUI_SS_DEFAULT_GUI
#include <GUIConstantsEx.au3> ; GUISetBkColor, $GUI_EVENT_CLOSE
#include <ButtonConstants.au3> ; $BS_DEFPUSHBUTTON
#include <StaticConstants.au3> ; $SS_CENTER
#Include <Misc.au3>; _Singleton
_Singleton(@ScriptName, 0); Single instant
Global $TimeLabel, $sMsg, $hMainwindow, $NoLaunch,$YesSelect,$NoSelect,$YESB
Global $s2ndlabel, $s3rdlabel,$s4thlabel, $s5thlabel, $s6thlabel, $s7thlabel, $s8thlabel, $i6thid
Global $TimeTicks, $begin, $_CompteArebour = 60000, $_Minutes, $_Seconds
Const $cGUIWid=620, $cGUIHt=650, $cHalfGUIWid=$cGUIWid/2

$hMainwindow= GUICreate("DOD BANNER", $cGUIWid, $cGUIHt, -1,-1, BitXOR($GUI_SS_DEFAULT_GUI, $WS_MINIMIZEBOX))
GUISetIcon (@WindowsDir&"\explorer.exe",0)

GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEClicked")
GUISetBkColor (0x3E4545) ; dark grey
GUICtrlCreateLabel ( "DOD NOTICE AND CONSENT BANNER", 40,10,550,20, $SS_CENTER)
GUICtrlSetFont (-1, 16, 440, 16, "helvetica" )
GUICtrlSetColor(-1, 0xFFFF00); Yellow font

$s2ndlabel="You are accessing a U.S. Government (USG) Information System (IS) that is provided for USG-authorized use only."
GUICtrlCreateLabel ($s2ndlabel, 40,35,570,45, $SS_CENTER)
GUICtrlSetFont (-1, 14, 380, 16, "helvetica" )
GUICtrlSetColor(-1, 0xFFFFF9); White font

$s3rdlabel="By using this IS(which includes any device attached to this IS), you consent to the following conditions:"
GUICtrlCreateLabel ($s3rdlabel, 40, 90, 550, 50, $SS_CENTER)
GUICtrlSetFont (-1, 11, 380, 16, "helvetica" )
GUICtrlSetColor(-1, 0x099099); Dark Green font

$s4thlabel="-The USG routinely intercepts and monitors communications on this IS "& _
"for purposes including, but not limited to, penetration testing, COMSEC"& _
" monitoring, network operations and defense, personnel misconduct (PM),"& _
" law enforcement (LE), and counterintelligence investigations (CI)."&@Lf&@Lf& _
"-At any time, the USG may inspect and seize data stored on this IS."&@Lf&@Lf& _
"-Communications using, or data stored on, this IS are not private, are"& _
" subject to routine monitoring, interception and search, and may be disclosed"& _
" or used for any USG-authorized purpose."&@Lf&@Lf& _
"-This IS includes security measures (e.g., authentication and access controls)"&@Lf&@Lf& _
"to protect USG interests--not for your personal benefit or privacy."& _
"-Notwithstanding the above, using this IS does not constitute consent to PM, LE,"&@Lf&@Lf& _
"or CI investigative searching or monitoring of the content of privileged"& _
"communications, or work product, related to personal representation or services"& _
"by attorneys, psychotherapists, or clergy, and their assistants. Such communication"& _
"and work product are private and confidential. See User Agreement for details."
GUICtrlCreateLabel ($s4thlabel, 40, 140, 550,250, $SS_CENTER)
GUICtrlSetFont (-1, 11, 380, 1, "helvetica" )
GUICtrlSetColor(-1, 0x099099); Dark Green font

$s5thlabel="I have read and consent to the terms of the IS User Agreement"
GUICtrlCreateLabel ($s5thlabel, 40, 400, 550,25, $SS_CENTER, $WS_EX_OVERLAPPEDWINDOW)
GUICtrlSetFont (-1, 12, 380, 16, "helvetica" )
GUICtrlSetColor(-1, 0xFFFFF9); White font

$s6thlabel="Remaining Time Before Auto Select NO "
$i6thid=GUICtrlCreateLabel ($s6thlabel, 100, 470, 550,25)
GUICtrlSetFont (-1, 15, 380, 16, "helvetica" )
GUICtrlSetColor(-1, 0xFFFF00); Yellow font

$TimeLabel = GUICtrlCreateLabel ( "", 460, 468, 50, 20 )
GUICtrlSetFont (-1, 15, 380, 16, "helvetica" )
GUICtrlSetColor(-1, 0xFFFF00)

$NoLaunch = GUICtrlCreateButton("NO", 250, 525, 60,-1,$BS_DEFPUSHBUTTON)
$YesSelect= GUICtrlCreateButton("YES", 330, 525, 60)

GUICtrlSetOnEvent($NoLaunch, "NoSelect")
GUICtrlSetOnEvent($YesSelect, "YESFunc")
GUISetState(@SW_SHOW)

$TimeTicks= TimerInit()

While 1
$sMsg = GUIGetMsg()
_Check ( )
Sleep(100) ; Just idle around
WEnd

Func NoSelect()
GUICtrlDelete ( $i6thid )
GUICtrlDelete ( $TimeLabel)
$s7thlabel="No Was Selected Cancel Operation"
GUICtrlCreateLabel ($s7thlabel, 40, 470, 550,25,$SS_CENTER)
GUICtrlSetFont (-1, 15, 380, 16, "helvetica" )
GUICtrlSetColor(-1, 0xFFFF00); Yellow font
sleep (1000)
Exit
EndFunc; EndFunc of NoSelect

Func YESFunc()
GUICtrlDelete ( $i6thid )
GUICtrlDelete ( $TimeLabel)
GUICtrlSetState ( $NoLaunch,$GUI_DISABLE )
$s8thlabel="Processing Yes Selection"
GUICtrlCreateLabel ($s8thlabel, 40, 470, 550,25,$SS_CENTER)
GUICtrlSetFont (-1, 15, 380, 16, "helvetica" )
GUICtrlSetColor(-1, 0xFFFF00); Yellow font
if FileExists (@scriptdir&"\BannerResult.cmd") then FileDelete (@scriptdir&"\BannerResult.cmd")
;Create The Temp Cmd File For Yes
FileWrite (@scriptdir&"\BannerResult.cmd","@Echo && CLS && MODE 55,5 && COLOR F9"&@crlf&"Set Reply=Yes"&@crlf)
Runwait (@scriptdir&"\BannerResult.cmd")
sleep (1000)
Exit
EndFunc

Func _Check ( )
$_CompteArebour -= TimerDiff ( $TimeTicks)
$TimeTicks = TimerInit ( )
Local $_MinCalc = Int ( $_CompteArebour / ( 60 * 1000 ) ), $_SecCalc = $_CompteArebour - ( $_MinCalc * 60 * 1000 )
$_SecCalc = Int ( $_SecCalc / 1000 )
If $_MinCalc <= 0 And $_SecCalc <= 0 Then
Exit
Else
If $_MinCalc <> $_Minutes Or $_SecCalc <> $_Seconds Then
$_Minutes = $_MinCalc
$_Seconds = $_SecCalc
GUICtrlSetData ( $TimeLabel, StringFormat ( "%02u" & ":" & "%02u", $_Minutes, $_Seconds ) )
If $_Minutes = 0 And $_Seconds <= 10 Then
Beep ( 1200, 100 )
GUICtrlSetColor ( $TimeLabel , 0xE70656); pink-red color
EndIf
EndIf
EndIf
EndFunc ;==> _Check ( )

Func CLOSEClicked()
Exit
EndFunc

I notice while HTA was running and clicking Start button, the start menu will disappear.

This does not happen using autoit.

Simple comparsion :

HTA in post 14 : 244 lines - 14 comment line =230 lines

Autoit: 134 lines - 1 comment line = 133 lines

Thanks again for the inspiration.

Screenshot: countdown >10 sec

sHyJr.png

Last 10 sec ...

Epgcs.png

Link to comment
Share on other sites

Here is a updated version at with 137 lines of code and can can be edit by something as simple as notepad.


<Title>My Demo Message Box</Title>
<HTA:APPLICATION ID="MyMessageBox"
SCROLL="No"
SCROLLFLAT ="No"
SingleInstance="Yes"
ShowInTaskbar="Yes"
SysMenu="Yes"
MaximizeButton="No"
MinimizeButton="No"
Border="Thin"
BORDERSTYLE ="complex"
INNERBORDER ="No"
Caption="Yes"
WindowState="Normal"
APPLICATIONNAME="MainApp"
Icon="%SystemRoot%\explorer.exe">
<STYLE type="text/css">
BODY{
Font-Size:8.25pt;
Font-Weight:Bold;
Font-Family:helvetica,verdana,arial;
Color:#008040;
BackGround-Color:Transparent;
filter:progid:DXImageTransform.Microsoft.Gradient(StartColorStr='#E2E2E2',EndColorStr='#6e6e6e);
Margin-Top:5;
Margin-Bottom:5;
Margin-Left:5;
Margin-Right:5;
Padding-Top:3;
Padding-Bottom:3;
Padding-Left:5;
Padding-Right:5;
Text-Align:Left;
Vertical-Align:Top;
}
TD.Type1{
Margin-Left:21;
Padding-Left:15;
}
BUTTON{
Height:18pt;
width:61pt;
Cursor:Hand;
Font:8.05pt;
Font-weight:bold;
Font-family:helvetica,verdana,arial;
Color:#404040;
Text-Align:Center;
Vertical-Align:Middle;
filter:progid:DXImageTransform.Microsoft.Gradient(StartColorStr='#E5E5E5',EndColorStr='#7D7D7D');
Margin:1;
Padding:2;
Border-Left: 1px Transparent;
Border-Right: 2px Transparent;
Border-Top: 1px Transparent;
Border-Bottom: 2px Transparent;
}
</STYLE>
<script Language='VBSCRIPT'>
Dim Act :Set Act = CreateObject("Wscript.Shell")
Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")
Dim Cmd :Cmd = Act.ExpandEnvironmentStrings("%Temp%") & "\MyReturn.cmd"
Dim Wth, Hht :Wth = int(425) :Hht = int(175)
window.ResizeTo Wth, Hht
MoveTo ((Screen.Width / 2) - (Wth / 2)),((Screen.Height / 2) - (Hht / 2))
Dim F1 :F1 = "<FONT STYLE='Font:8.25pt;Color:#002060;Font-Weight:Bold;'>"
Dim idTimer, Y_DoIt
Dim C1, D1 :C1 = 30 :D1 = 1
Function Window_OnLoad()
Counter()
txt1.innerHTML = F1 & "Ask Your Question About What You Want Done</FONT>"
txt2.innerHTML = F1 & "Here Is Some More Text Space For You If Needed</FONT>"
End Function
Function Counter()
Do
D1 = D1 -1 :C1 = C1 -1 :document.focus()
If Len(C1) = 1 Then C1 = "0" & C1
If Len(C1) = 2 Then C1 = C1
txt3.innerHTML = F1 & "Remaining Time Before Auto Select Yes " & C1 & "</FONT>"
Loop Until D1 = 0
D1 = 1
If C1 = 0 Then
Y_DoIt = True
HtaExit()
Exit Function
End if
idTimer = window.setTimeout("Counter", 1000, "VBScript")
If Y_DoIt = True Then Yes_Work()
End Function
Function No_Action()
Bttn_Y.disabled = True
txt3.innerHTML = Replace(F1,"002060","AD0101") & "No Was Selected Cancel All Operation</FONT>"
MkCmd("No")
window.clearTimeout(idTimer)
idTimer = window.setTimeout("MyTimer2", 5000, "VBScript")
Exit Function
End Function
Function Yes_Action()
Y_DoIt = True
End Function
Function Yes_Work()
Bttn_N.disabled = True
txt3.innerHTML = Replace(F1,"002060","006020") & "Processing Yes Selection</FONT>"
MkCmd("Yes")
window.clearTimeout(idTimer)
idTimer = window.setTimeout("MyTimer1", 3000, "VBScript")
End Function
Function HtaExit()
window.clearTimeout(idTimer)
If Y_DoIt = True Then Yes_Work()
End Function
Function MyTimer1()
txt3.innerHTML = ""
window.close()
window.clearTimeout(idTimer)
End Function
Function MyTimer2()
txt3.innerHTML = ""
window.close()
window.clearTimeout(idTimer)
End Function
Function MkCmd(T)
Dim Ts : Set Ts = Fso.CreateTextFile(Cmd)
Ts.WriteLine "@Echo && CLS && MODE 55,5 && COLOR F9"
Ts.WriteLine "Set Reply=" & T
Ts.Close
End Function
</SCRIPT>
<BODY Scroll='No'>
<Table><TD Class='Type1'><Span ID='txt1'></Span></TD></Table>
<Table><TD Class='Type1'><Span ID='txt2'></Span></TD></Table>
<Table><TD Class='Type1'><Span ID='txt3'></Span></TD></Table>
<Table Style='Margin-Top:7pt;' Align='Center'>
<TD><BUTTON ID='Bttn_N' OnClick='No_Action()'>No</BUTTON></TD>
<TD><BUTTON ID='Bttn_Y' OnClick='Yes_Action()'>Yes</BUTTON></TD>
</Table>
</BODY>

post-5386-0-34633700-1325738701_thumb.pn

YesNo_Updated.zip

I also wrote this 39 lines of code with comments in Vb.net 2008


Imports System
Imports System.IO
Public Class Form1
Dim Yes
Dim C1 = 30
'-> Stsrt Timer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Start()
End Sub
'-> Yes
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Yes = 1
End Sub
'-> No
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Yes = 2
End Sub
'-> Start The Timer
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
CountDown()
End Sub
'-> Count Down
Private Sub CountDown()
If C1 < 10 Then C1 = "0" & C1
If Yes = 1 Then MakeCmd("Yes")
If Yes = 2 Then MakeCmd("No")
If C1 = 0 Then MakeCmd("Timed-Out")
Counter.Text = "Time Left : " & C1
C1 = C1 - 1
End Sub
'-> Make Reply Cmd With Yes No Time Out
Private Sub MakeCmd(ByVal T As String)
Dim Cmd = My.Computer.FileSystem.SpecialDirectories.Temp & "\MyReturn.cmd"
Dim sw As StreamWriter = New StreamWriter(Cmd)
sw.Write("Set Reply=" & T)
sw.Close()
Me.Close()
End Sub
End Class

post-5386-0-08237000-1325744605_thumb.pn

VB.Net 2006 Source Code

YesNo_Demo.zip

Cmd Promt I Used To Read The Responce


@Echo Off
CLS
Mode 79,11
Color F9
Title Test Return


Set Cmd1="%Temp%\MyReturn.cmd"

If Exist %Cmd1% GoTO Work1
If Not Exist %Cmd1% GoTO Ops1


:Work1
call %Cmd1%
CLS
IF /I '%Reply%'=='Yes' GOTO Y1
IF /I '%Reply%'=='No' GOTO N1
IF /I '%Reply%'=='Timed-Out' GOTO T1

Goto TheEnd

:Ops1
Color F5
CLS
Echo.
Echo Missing %Cmd1%
Echo Contact The System Admin For More Information!
pause
Exit

:Y1
CLS
Echo.
Echo User Selected : %Reply%
Echo.
Pause
GoTo TheEnd

:N1
CLS
Echo.
Echo User Selected : %Reply%
Echo.
Pause
GoTo TheEnd

:T1
CLS
CLS
Echo.
Echo Auto Action : %Reply%
Echo.
Pause
GoTo TheEnd

:TheEnd
Del %Cmd1%
Exit

Link to comment
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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...