esullivan Posted March 6, 2015 Share Posted March 6, 2015 (edited) Does anyone have a shutdown script that has the option to postpone if a user is on the computer? With a countdown timer? Or would anyone be kind enough to whip one up? I basicly want this to run with a message that gives the user, if there is one, the option to postpone, say 30 mintues. But it will never stop. Once the message comes up the user has 3 minutes (with a timer) or so to postpone, but every 30 mintues it will ask until it shuts down. Thanks for any help Edited March 6, 2015 by esullivan Link to comment Share on other sites More sharing options...
Radiance Posted March 6, 2015 Share Posted March 6, 2015 (edited) While/WEnd TimerInit() TimerDiff() MsgBox() Shutdown() That are the functions you will need. Now go and figure out how to put it together. Edited March 6, 2015 by Radiance Link to comment Share on other sites More sharing options...
esullivan Posted March 6, 2015 Author Share Posted March 6, 2015 (edited) I have been trying to I have very basic skills in programming. I have been and will keep trying (Thanks for the tips), just hoping someone maybe had something already. Edited March 6, 2015 by esullivan Link to comment Share on other sites More sharing options...
MikahS Posted March 6, 2015 Share Posted March 6, 2015 Post what you have been trying. Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ Link to comment Share on other sites More sharing options...
esullivan Posted March 6, 2015 Author Share Posted March 6, 2015 LOL, it's been VERY basic in fact I deleted what I had last. Once I have some time, I am going to look through what wayfarer posted and see if I can do better. I am VERY new to AutoIT, but I know a little more VB (which is similar). Link to comment Share on other sites More sharing options...
MikahS Posted March 6, 2015 Share Posted March 6, 2015 We all were beginners once. Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ Link to comment Share on other sites More sharing options...
pcjunki Posted March 6, 2015 Share Posted March 6, 2015 Or would anyone be kind enough to whip one up? sure, I'm right all over this! Link to comment Share on other sites More sharing options...
MikahS Posted March 6, 2015 Share Posted March 6, 2015 sure, I'm right all over this! I made the mistaken of being sarcastic once. Now there is this: >link Use my mistake and do not post unless you have something constructive, like I should have. Thanks, MikahS Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ Link to comment Share on other sites More sharing options...
TheDcoder Posted March 6, 2015 Share Posted March 6, 2015 (edited) While 1 Sleep(1000 * 1 * 60 * 30) AskForShutdown() WEnd Func AskForShutdown() $answer = MsgBox(4 + 48, "Shutdown?", "Do you wanna postphone the shutdown?", 1 * 60 * 3) If $answer = 7 Then Shutdown(BitOR($SD_SHUTDOWN, $SD_POWERDOWN)) ElseIf $answer = -1 Shutdown(BitOR($SD_SHUTDOWN, $SD_POWERDOWN)) EndIf EndFunc TD Edited March 6, 2015 by TheDcoder esullivan 1 EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
pcjunki Posted March 6, 2015 Share Posted March 6, 2015 I made the mistaken of being sarcastic once. Now there is this: >link Use my mistake and do not post unless you have something constructive, like I should have. Thanks, MikahS read and understood MikahS 1 Link to comment Share on other sites More sharing options...
MikahS Posted March 6, 2015 Share Posted March 6, 2015 Have a look at this link esullivan: >Prevent Shutdown/Sleep Snips & Scripts My Snips: graphCPUTemp ~ getENVvarsMy Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4 Feel free to use any of my code for your own use. Forum FAQ Link to comment Share on other sites More sharing options...
Solution spudw2k Posted March 6, 2015 Solution Share Posted March 6, 2015 (edited) If it were me I'd make a countdown that is presented to the user, give them the option to postpone, act now or do nothing. Here's a simple countdown GUI. expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <SendMessage.au3> #include <Date.au3> Opt("TrayMenuMode", 1) $iDuration = 60 ;Countdown Timer in Seconds $sTitle = "Countdown Timer" $sMessage = "Something is going to happen " & @CRLF & "when this countdown completes." $sButton1 = "Do it now" $sButton2 = "Postpone" $iReturn = _CountdownGUI($iDuration, $sTitle, $sMessage, $sButton1, $sButton2) If $iReturn Then MsgBox(0,"","Button " & $iReturn & " Clicked") Else Msgbox(0,"","No action taken" & @CRLF & "Timer Expired") EndIf Func _CountdownGUI($iDuration = 60, $sTitle = "Countdown Timer", $sMessage = "", $sButton1 = "Yes", $sButton2 = "No", $dTitleBKColor = "0x3399FF", $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 Edited March 6, 2015 by spudw2k esullivan 1 Spoiler Things I've Made: Always On Top Tool ◊ AU History ◊ Deck of Cards ◊ HideIt ◊ ICU ◊ Icon Freezer ◊ Ipod Ejector ◊ Junos Configuration Explorer ◊ Link Downloader ◊ MD5 Folder Enumerator ◊ PassGen ◊ Ping Tool ◊ Quick NIC ◊ Read OCR ◊ RemoteIT ◊ SchTasksGui ◊ SpyCam ◊ System Scan Report Tool ◊ System UpTime ◊ Transparency Machine ◊ VMWare ESX Builder Misc Code Snippets: ADODB Example ◊ CheckHover ◊ Detect SafeMode ◊ DynEnumArray ◊ GetNetStatData ◊ HashArray ◊ IsBetweenDates ◊ Local Admins ◊ Make Choice ◊ Recursive File List ◊ Remove Sizebox Style ◊ Retrieve PNPDeviceID ◊ Retrieve SysListView32 Contents ◊ Set IE Homepage ◊ Tickle Expired Password ◊ Transpose Array Projects: Drive Space Usage GUI ◊ LEDkIT ◊ Plasma_kIt ◊ Scan Engine Builder ◊ SpeeDBurner ◊ SubnetCalc Cool Stuff: AutoItObject UDF ◊ Extract Icon From Proc ◊ GuiCtrlFontRotate ◊ Hex Edit Funcs ◊ Run binary ◊ Service_UDF Link to comment Share on other sites More sharing options...
zalomalo Posted March 7, 2015 Share Posted March 7, 2015 (edited) Dont show two buttons in order the user clic one, or the user will click random one (or not random but without knowing what the button means). Just show one button to give more time, if no user at the screen = button no clicked. Post redundant ?. Ups sorry. Edited March 7, 2015 by zalomalo My english shucks, i know it. Link to comment Share on other sites More sharing options...
esullivan Posted March 7, 2015 Author Share Posted March 7, 2015 (edited) Thanks spud! That's perfect! I have made the modifications I want, but I have one question. Below is what I changed, the shutdown now and timer expired are cake. But for the postpone, how would I wait then loop back up to show the popup and start the process again? If $iReturn = 1 Then msgbox(0,"","Shutdown now") Elseif $iReturn = 2 Then ;How do I loop back up and start again? msgbox(0,"","Postpone shutdown 30 minutes") Else msgbox (0,"","Timer expired") EndIf Thanks for all your help!! Edited March 7, 2015 by esullivan Link to comment Share on other sites More sharing options...
TheDcoder Posted March 7, 2015 Share Posted March 7, 2015 @esullivan Look at my previous post EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
esullivan Posted March 7, 2015 Author Share Posted March 7, 2015 (edited) Sorry prod, I am looking at this code, and I don't see how it restarts? I am trying to learn AutoIT whilst I am doing this too, explaination? I don't want it to just postpone for a time then just shut down. I want the dialog to go away for a time then pop back up to basicly start the process again. This way the user has the option to postpone every 30 mintutes as long as they are on the computer. Thanks! Edited March 7, 2015 by esullivan Link to comment Share on other sites More sharing options...
TheDcoder Posted March 7, 2015 Share Posted March 7, 2015 @esullivan Adlib runs a function between specified time intervals, so first make a simple function & adlibregister it EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
esullivan Posted March 7, 2015 Author Share Posted March 7, 2015 Think I got it! Testing now. TheDcoder 1 Link to comment Share on other sites More sharing options...
TheDcoder Posted March 7, 2015 Share Posted March 7, 2015 Think I got it! Testing now. Happy to help esullivan 1 EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
esullivan Posted March 7, 2015 Author Share Posted March 7, 2015 Final code that works perfect! Thanks guys! expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <StaticConstants.au3> #include <SendMessage.au3> #include <Date.au3> #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 TheDcoder 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now