#include #include #include #include #include #AutoIt3Wrapper_icon=Shutdown.ico Opt("TrayMenuMode", 1) Func Postpone() Sleep(1000 * 1 * 60 * 30) AskForShutdown() EndFunc AskForShutdown() Func AskForShutdown() $iDuration = 60 ;Countdown Timer in Seconds $sTitle = "ASD Countdown Timer" $sMessage = "This computer will shutdown " & @CRLF & "when this countdown completes." $sButton1 = "Do it now" $sButton2 = "Postpone" $iReturn = _CountdownGUI($iDuration, $sTitle, $sMessage, $sButton1, $sButton2) If $iReturn = 1 Then Shutdown(BitOR($SD_SHUTDOWN, $SD_POWERDOWN)) Elseif $iReturn = 2 Then Postpone() Else Shutdown(BitOR($SD_SHUTDOWN, $SD_POWERDOWN)) EndIf EndFunc Func _CountdownGUI($iDuration = 60, $sTitle = "Countdown Timer", $sMessage = "", $sButton1 = "Yes", $sButton2 = "No", $dTitleBKColor = "0x0F4400", $dTitleTextColor = "0xFFFFFF") ;Create GUI Window Local $hGUI = GUICreate($sTitle, 350, 230, -1, -1, $WS_POPUPWINDOW, $WS_EX_TOPMOST) ;Title Window Portion GUICtrlSetDefBkColor($dTitleBKColor) GUICtrlCreateLabel("",0,0,350,10) GUICtrlCreateLabel($sTitle, 0, 10, 350, 30, $SS_CENTER) GUICtrlSetColor(-1, $dTitleTextColor) GUICtrlSetFont(-1, 12, 700) GUICtrlSetDefBkColor("0xF0F0F0") ;Message Area GUICtrlCreateLabel("",0,40,350,20) GUICtrlCreateLabel($sMessage, 0, 60, 350, 70, $SS_CENTER) GUICtrlSetFont(-1, 10, 700) ;Timer Area GUISetFont(12, 700) Local $idTimer = GUICtrlCreateLabel("00:00:00", 0, 130, 350, 30, $SS_CENTER) ;Buttons GUISetFont(10, 0) Local $idButton1 = GUICtrlCreateButton($sButton1, 50, 180, 100, 30) Local $idButton2 = GUICtrlCreateButton($sButton2, 202, 180, 100, 30) ;Function Return Variable Local $iReturn = 0 ;Display Countdown GUI GUISetState(@SW_SHOW) ;Setup Countdown Time Variable $iCountdown = $iDuration ;Setup Countdown Update Timer and Set Countdown Local $hRefreshTimer = TimerInit() GUICtrlSetData($idTimer, _CountDownCalc($iCountdown)) $iCountdown -= 1 ;GUI Loop While Not $iReturn ;GUI Countdown Update If TimerDiff($hRefreshTimer) >= 999 Then $hRefreshTimer = TimerInit() GUICtrlSetData($idTimer, _CountDownCalc($iCountdown)) $iCountdown -= 1 If $iCountdown < 0 Then ExitLoop EndIf ;GUI Events $aMsg = GUIGetMsg(1) Switch $aMsg[0] Case $idButton1 $iReturn = 1 Case $idButton2 $iReturn = 2 EndSwitch WEnd ;Kill GUI GUIDelete($hGUI) Return $iReturn EndFunc Func _CountDownCalc($iCountdown) ;Special thanks to careca - http://www.autoitscript.com/forum/topic/162789-timer-with-000/?p=1184285 $iHour = Int($iCountdown / 3600) $iMin = Int(($iCountdown - $iHour * 3600) / 60) $iSec = $iCountdown - $iHour * 3600 - $iMin * 60 Return StringFormat('%02d:%02d:%02d', $iHour, $iMin, $iSec) EndFunc