RedneckTech Posted March 1, 2012 Share Posted March 1, 2012 (edited) 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.expandcollapse popup#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 WEndJust replace <DesiredTime> with your idle time in ms, put in your startup folders and youre good to go!XP: C:Documents and SettingsAll UsersStart MenuProgramsStartup7: 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 March 1, 2012 by RedneckTech Link to comment Share on other sites More sharing options...
Tóth Zsigmond Posted November 14, 2021 Share Posted November 14, 2021 (edited) expandcollapse popup#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 November 14, 2021 by Tóth Zsigmond Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 14, 2021 Moderators Share Posted November 14, 2021 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 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 columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area 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