Jump to content

Shutdown timer


RedneckTech
 Share

Recommended Posts

So I was working on something this morning that can be very useful seeing as we all have users who dont know how to shutdown, particularly lawyers and insurance guys.

Originally written as per request from a family member to stop annoying kids from never shutting down the thing.

Figured id share it with the world.

#include <Timers.au3>
#include <Date.au3>
#include <File.au3>

$Timeout = <Desired time (ms!)>
$Directory = "C:ShutdownLog"
$File = "C:ShutdownLogLog.txt"
$uFile = @UserProfileDir & "SDLog.txt"
$LFile = @UserProfileDir & "LogonLog.txt"
$FileHandle = FileOpen($File, 1)
$uFileHandle = FileOpen($uFile, 1)
$LFileHandle = FileOpen($LFile, 1)
$n=1
$SDCount = _FileCountLines($uFileHandle)
$LCount = _FileCountLines ($LFileHandle)

If FileExists($File) = 0 Then
   DirCreate($Directory)
   FileWriteLine($uFileHandle, "This File Contains:" & @LF & "A Log of all unwanted shutdowns on this user" & @LF)
   FileWriteLine($LFileHandle, "Logons for this User:" & @LF)
EndIf

FileWriteLine ($LFileHandle, "Logon at: " & _NowCalc & @LF)
FileClose ($LFile)

$Math = $SDCount / $LCount
If $Math >= 0.5 Then
   MsgBox( 0, "Hey You!", "You REALLY need to learn to Shutdown before you just walk away!")
EndIf

While $n=1
   $TimeIdle = _Timer_GetIdleTime()
   If $TimeIdle >= $Timeout Then
   FileWriteLine ($FileHandle, "Shutdown at: " & _NowCalc() & " Logged on user was: " & @UserName & @LF)
   FileWriteLine ($uFileHandle, "Shutdown at: " & _NowCalc() & " while you were logged on" & @LF)
   $n=2
   Shutdown (5)
   EndIf
WEnd

Just replace <DesiredTime> with your idle time in ms, put in your startup folders and youre good to go!

XP: C:Documents and SettingsAll UsersStart MenuProgramsStartup

7: C:ProgramDataMicrosoftWindowsStart MenuProgramsStartup (Its a hidden system folder!)

Thanks to

somdcomputerguy

for helping me out with this one.

Note: as seen in DO NOT run the following line in a script:

Run (@ComSpec & " /c " & "Shutdown.exe -s -t 01", "", @SW_HIDE)

Not sure why, but the comptuer freaks out and then you when it actually does shut down you get to wait 20 minutes and then hold the power button down to shut it down and then when your computer doesnt come back alive you have to pull out the battery. (Tested twice)

Enjoy!

Edit: changed Shutdown(13) to Shutdown(5) so as to remove the powerdown function. thanks to user 69255

Edited by RedneckTech
Link to comment
Share on other sites

  • 9 years later...
#NoTrayIcon
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <UpdownConstants.au3>


Global $Time, $Paused = 1, $sum, $display = 1

HotKeySet("{PAUSE}", "TogglePause")

$Form2 = GUICreate("Shutdown Menu", 413, 179, 192, 123)
$Input1 = GUICtrlCreateInput("0", 76, 128, 73, 21)
$Updown1 = GUICtrlCreateUpdown($Input1, BitOR($UDS_ALIGNRIGHT, $UDS_ARROWKEYS, $UDS_NOTHOUSANDS))
GUICtrlSetLimit(-1, 168, 0)
$Label1 = GUICtrlCreateLabel("Seconds:", 264, 104, 49, 17)
GUICtrlSetFont(-1, 9, 400, 0, "MS Sans Serif")
$Input2 = GUICtrlCreateInput("0", 168, 128, 73, 21)
$Updown2 = GUICtrlCreateUpdown($Input2, BitOR($UDS_ALIGNRIGHT, $UDS_ARROWKEYS, $UDS_NOTHOUSANDS))
GUICtrlSetLimit(-1, 59, 0)
$Label2 = GUICtrlCreateLabel("Minutes:", 168, 104, 44, 17)
GUICtrlSetFont(-1, 9, 400, 0, "MS Sans Serif")
$Input3 = GUICtrlCreateInput("0", 264, 128, 73, 21)
$Updown3 = GUICtrlCreateUpdown($Input3, BitOR($UDS_ALIGNRIGHT, $UDS_ARROWKEYS, $UDS_NOTHOUSANDS))
GUICtrlSetLimit(-1, 59, 0)
$Label3 = GUICtrlCreateLabel("Hours:", 74, 104, 35, 17)
GUICtrlSetFont(-1, 9, 400, 0, "MS Sans Serif")
$Button1 = GUICtrlCreateButton("Hibernate", 16, 16, 89, 33, $WS_GROUP)
$Button2 = GUICtrlCreateButton("Stand By", 112, 16, 89, 33, $WS_GROUP)
$Button3 = GUICtrlCreateButton("Shutdown", 208, 16, 89, 33, $WS_GROUP)
$Button4 = GUICtrlCreateButton("Restart", 304, 16, 89, 33, $WS_GROUP)
$Button5 = GUICtrlCreateButton("Log Off", 160, 51, 89, 33, $WS_GROUP)
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
         Case $Button1
            Global $type="Hibernate"
            Countdown()
         Case $Button2
            Global $type="Stand By"
            Countdown()
         Case $Button3
            Global $type="Shutdown"
            Countdown()
         Case $Button4
            Global $type="Restart"
            Countdown()
         Case $Button5
            Global $type="Log Off"
            Countdown()
    EndSwitch
    If $Paused = -1 And $display Then
        ToolTip('Script is "Paused"', 0, 0)
        $display = 0
    EndIf
    If $Paused = 1 Then ToolTip("")

WEnd

Func Countdown()
    $Sec = GUICtrlRead($Input3)
    $Min = GUICtrlRead($Input2)
    $Hour = GUICtrlRead($Input1)
    $sum = $Sec + 60 * $Min + 3600 * $Hour
    AdlibRegister("Counter", 1000)
EndFunc   ;==>Timer

Func Counter()
    Local $s, $m, $Hour
    If $sum = 0 Then
        AdlibUnRegister("Counter")
        $display = 1
    Else
        $sum -= 1
        $s = Mod($sum, 60)
        $m = Mod(Int($sum / 60), 60)
        $h = Int($sum / 60 ^ 2)
        GUICtrlSetData($Input3, $s)
        GUICtrlSetData($Input2, $m)
        GUICtrlSetData($Input1, $h)

         If $h=0 Then
           If $m=0 Then
              If $s=0 Then

                 if $type="Hibernate" Then
                     Shutdown(64)
                 EndIf

                 if $type="Stand By" Then
                     Shutdown(32)
                 EndIf

                 if $type="Shutdown" Then
                     Shutdown(1)
                 EndIf

                 if $type="Restart" Then
                     Shutdown(6)
                 EndIf

                 if $type="Log Off" Then
                     Shutdown(0)
                 EndIf

                 EndIf
              EndIf
           EndIf

    EndIf
EndFunc


Func TogglePause()
    $Paused *= -1
    If $Paused -1 Then
        AdlibUnRegister("Counter")
    Else
        AdlibRegister("Counter", 1000)
    EndIf
EndFunc   ;==>TogglePause

Full Worked end Stuff->

 

Edited by Tóth Zsigmond
Link to comment
Share on other sites

  • Moderators

Tóth Zsigmond,

You do realise that the last post in this thread was 9 years ago?

Please do not necro-post like this in future.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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...