Jump to content

Shutdown Script


Go to solution Solved by spudw2k,

Recommended Posts

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 by esullivan
Link to comment
Share on other sites

Post what you have been trying. :)

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My 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

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

We all were beginners once. ;)

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My 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

sure, I'm right all over this!

:shifty:

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 ~ getENVvars
My 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

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 by TheDcoder

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

Have a look at this link esullivan: >Prevent Shutdown/Sleep

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My 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

  • Solution

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.

#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 by spudw2k
Link to comment
Share on other sites

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 by zalomalo

My english shucks, i know it.

Link to comment
Share on other sites

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 by esullivan
Link to comment
Share on other sites

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 by esullivan
Link to comment
Share on other sites

Final code that works perfect!  Thanks guys!

#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
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
 Share

  • Recently Browsing   0 members

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