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
Last 10 sec ...