Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Countdown to Shutdown


  • Please log in to reply
3 replies to this topic
MordyT
  • Members
  • 7 posts
  • Last active: Dec 09 2013 12:54 PM
  • Joined: 18 Aug 2013

I work at a school running windows 7.

The shutdown command does not work the same way it used to on XP, due to session isolation there is no countdown timer.

 

AHK to the rescue, this script is meant to give a 2 minute warning, then shutdown the PC. There should be no way to cancel this. We call it via scheduled task...

 

#SingleInstance, force

initSecs := 120 ; number of seconds to wait

#NoTrayIcon

Gui, 99:+AlwaysOnTop +Disabled -SysMenu +Owner
Gui, 99:Font,s20 bold,Verdana
Gui, 99:Add, Text,, Please save and close all work.
Gui, 99:Add, Text,, This system will shutdown in
Gui, 99:Add, Text, x470 y70 w90 h30 vTX , %initSecs%
Gui, 99:Show, NoActivate, WARNING! ; NoActivate avoids deactivating the currently active window.
Gui, 99:Flash

loop % initSecs-1 {        
    GuiControl,99:,TX,% Frmt(--initSecs)
    sleep, 1000
}
Gui, 99:Destroy

Shutdown, 5

return

Frmt(secs) {
    time = 20000101
    time += %secs%, seconds
    FormatTime, mmss, %time%, mm:ss
    return mmss
}


ErrorOnLine1
  • Members
  • 230 posts
  • Last active: Oct 05 2015 02:46 PM
  • Joined: 25 Dec 2012
@MordyT
 
I liked your style of commenting in your Basic Form script. Also, I checked out your blog. For someone like me who can't get past battery cables, the trouble-shooting of electrical problems in your 92 Camry was awe inspiring! 
 
Here's my take on a system shutdown script ... 
Spoiler


MordyT
  • Members
  • 7 posts
  • Last active: Dec 09 2013 12:54 PM
  • Joined: 18 Aug 2013

@erroronline1

Thanks.

 

I have since done many updates, the biggest one is moving the settings to a ini file...

 

here is the new version.

 

i did not write all the code in here, some of it was copy/pasta from other scripts (it's how I learn). The ini file needs to be called timer.ini and be in the same dir as the exe/ahk.

 

AHK:

;System to provide a countdown timer.
;Written by MordyT (mordyt.com)
;License granted to free / personal / educational use only. Commercial users need to contact me.

;Only run one at a time
#SingleInstance, force

;Get the time from the ini file...
IniRead, countdown, %A_ScriptDir%\Timer.ini, settings, seconds

;or we can hard code it in...
;countdown := 120 ; number of seconds to wait

;No tray icon
#NoTrayIcon

;Build a GUI

;Make it stay on top, disable the window, omit the minimize, maximize, and close buttons, and avoid a taskbar button
Gui, 99:+AlwaysOnTop +Disabled -SysMenu +Owner

;Make it big!
Gui, 99:Font,s20 bold,Verdana

;Add the words in now
Gui, 99:Add, Text,, Please save and close all work.
Gui, 99:Add, Text,, This system will shutdown in
Gui, 99:Add, Text, x470 y70 w90 h30 vTX , %countdown%

;Make it appear in front, but don't steal the mouse. Also, set the title bar.
Gui, 99:Show, NoActivate, WARNING!

;Make it have a tantrum and call attention by flashing!
Gui, 99:Flash

;Ooh, GUI is all done, now to work... start the countdown...
loop % countdown-1 {
GuiControl,99:,TX,% Frmt(--countdown)
sleep, 1000
}

;Blow the GUI up!
Gui, 99:Destroy

;Should we shutdown?
IniRead, poweroff, %A_ScriptDir%\Timer.ini, settings, powerdown

if (poweroff == "Yes")
{
Shutdown, 5
return
}
else
{
return
}

return

;make the time preety!
Frmt(secs) {
time = 20000101
time += %secs%, seconds
FormatTime, mmss, %time%, mm:ss
return mmss
}

INI:

[Settings]
Seconds=120
powerdown=Yes


yrtsh
  • Members
  • 13 posts
  • Last active: Dec 17 2017 08:24 AM
  • Joined: 11 Feb 2015

little count down I found (show near the mouse is)

;;;;;;;;;;;;;;;;;;SHOW COUNT DONWN near the mouse
Loop 20
{
ToolTip, % 21 - A_Index ; if you just use A_Index it starts at 1 2 3 etc
Sleep 1000
}
Tooltip, 0