Kaimberex Posted September 25, 2015 Share Posted September 25, 2015 (edited) I am in the IT department and I have been asked to create a SCCM reboot timer used when the computer requires a restart. What I am having trouble doing is changing the timer based on a combo box selection. For instance the default timer is 2 hours before the computer will be restarted. but I want to change the timer to a different value if the user selects a different time. I can get the default time to work just not stop the timer and create a new one. I am still pretty new to Autoit and could use some help. Thanks. Here is an example of what I have so far. expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <ComboConstants.au3> #include <GUIConstants.au3> $ms = 7200000 $timer = TimerInit() #Region ### START Koda GUI section ### Form= Global $Form1 = GUICreate("Form1", 464, 283, 670, 390,$WS_POPUP) GUISetBkColor(0x004c92) Global $Pic1 = GUICtrlCreatePic("C:\Manual\Development\AutoIt\SCCM Reboot Tool\Logo.jpg", 8, 8, 105, 41) Global $Pic2 = GUICtrlCreatePic("C:\Manual\Development\AutoIt\SCCM Reboot Tool\Logo.jpg", 349, 7, 105, 41) Global $Button1 = GUICtrlCreateButton("Minimize", 8, 241, 121, 25) Global $Button2 = GUICtrlCreateButton("Restart", 335, 241, 121, 25) Global $Button3 = GUICtrlCreateButton("Postpone", 195, 242, 73, 25) Global $Label1 = GUICtrlCreateLabel("Restart in Progress", 128, 8, 209, 33) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif") GuiCtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) Global $Label1 = GUICtrlCreateLabel("AGCS IT has deployed an update to your computer that requires a" & @CRLF & "reboot. Please restart your computer or postpone to a more convenient" & @CRLF & "time within the specified 8 hour limit. Thanks for your co-operation.", 24, 80, 420, 73,$SS_CENTER) GUICtrlSetColor(-1, 0xFFFFFF) GuiCtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) Global $Label2 = GUICtrlCreateLabel("", 160, 184, 145, 21,BitOr($SS_CENTER, $ES_READONLY)) GUICtrlSetColor(-1, 0xFFFFFF) GuiCtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) Global $TimeCombo = GUICtrlCreateCombo("10 minutes", 160, 208, 145, 25, BitOR($CBS_DROPDOWN,$CBS_AUTOHSCROLL)) GUICtrlSetData(-1, "20 minutes|30 minutes|1 hour|2 hours|6 hours") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While (TimerDiff($timer) < $ms) and (GUIGetMsg() <> $Button2) $seconds = TimerDiff($timer)/1000 $diff = $seconds - ($ms/1000) ; $minutes = Int($diff / 60) $secondsRem = $diff - ($minutes * 60) ; $minutes = $minutes * -1 $secondsRem = $secondsRem * -1 $time = StringFormat("%02d", $minutes) & ":" & StringFormat("%02d", $secondsRem) ; GUICtrlSetData($Input1, $time) $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $TimeCombo Switch GUICtrlRead($TimeCombo) Case "10 minutes" Seconds30() EndSwitch EndSwitch WEnd Func Seconds30() While (TimerDiff($timer) < $ms) and (GUIGetMsg() <> $Button2) $seconds = TimerDiff($timer)/1000 $diff = $seconds - ($ms/1000) ; $minutes = Int($diff / 60) $secondsRem = $diff - ($minutes * 60) ; $minutes = $minutes * -1 $secondsRem = $secondsRem * -1 $time = StringFormat("%02d", $minutes) & ":" & StringFormat("%02d", $secondsRem) ; GUICtrlSetData($Label2, $time) WEnd EndFunc MsgBox(0,0,1) Edited September 25, 2015 by Kaimberex Fixed error in code Link to comment Share on other sites More sharing options...
ViciousXUSMC Posted September 25, 2015 Share Posted September 25, 2015 (edited) I'd probably just send the standard cmd prompt and set the time from there. Use your GUI instead of an input box to set the value.$iTime = InputBox("Restart Time", "Enter Number of Minutes Until Restart", "2") If @Error Then Exit Run(@ComSpec & " /c shutdown /r /f /t " & $iTime)The reason I do not use Timer() functions is that they seem to be unreliable to me. Using date/time functions however is not a bad way to go then it can base the time off the system time. Edited September 25, 2015 by ViciousXUSMC Link to comment Share on other sites More sharing options...
Kaimberex Posted September 25, 2015 Author Share Posted September 25, 2015 I'd probably just send the standard cmd prompt and set the time from there. Use your GUI instead of an input box to set the value.$iTime = InputBox("Restart Time", "Enter Number of Minutes Until Restart", "2") If @Error Then Exit Run(@ComSpec & " /c shutdown /r /f /t " & $iTime)The reason I do not use Timer() functions is that they seem to be unreliable to me. Using date/time functions however is not a bad way to go then it can base the time off the system time.I actually have it being sent to change the label. I had just used an old variable to test it and forgot to change it I updated it. Link to comment Share on other sites More sharing options...
ViciousXUSMC Posted September 25, 2015 Share Posted September 25, 2015 This could be fun, somebody will probably beat me to it, but I would use AdlibRegister() to call my GUI with the message and restart/postpone message.I would also have it set for a maximum of say 3 postpone attempts before it forces the reboot.From experience the more obnoxious you make it the more prone somebody is to actually reboot else they ignore it. So I would have a GUI with the current minutes left until the next action on screen somewhere so that it nags them, and maybe a pop up message every so often to remind them they need to reboot The way I like to do updates best is Wake on LAN all PC after hours, and do the updates with a forced reboot. Link to comment Share on other sites More sharing options...
Kaimberex Posted September 25, 2015 Author Share Posted September 25, 2015 we force our users to take their machines home everynight so doing them after hours only works on dekstops. most users have laptops. My manager approcahed me and asked me to improve on their current shutdown tool and I was trying to mirror the current one before adding new functionality. currently I can only get the default time of 2 hours to count down then process the restart. and If there are easier ways to do it without nagging the user id like that. the users are having the prompt come up during presentations at bord meetings and inopportune times so I will eventually add a feature to only pop up once powerpoint or webex process is not running. however I would like to at least get the core tool working first. our IT department used the Coretech Shutdown tool currently and it is missing some features and they knew I liked scripting things so I kind of agreed to see what I can do. I hope I dont fail miserably. Is there an easier countdown? Time functions is one thing im still trying to grasp the understanding of. so any help with example snippets is appreciated. Link to comment Share on other sites More sharing options...
Kaimberex Posted September 25, 2015 Author Share Posted September 25, 2015 (edited) SO i have made some modifications to get the timer to change based on cases of the dropdowns and it changes the timer. but it performs the function immediately instead of waiting for the timer to hit 00:00 I am sure I am missing something simple. expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <ComboConstants.au3> #include <GUIConstants.au3> #Region ### START Koda GUI section ### Form= Global $Form1 = GUICreate("Form1", 464, 283, 670, 390, $WS_POPUP) GUISetBkColor(0x004c92) Global $Pic1 = GUICtrlCreatePic("C:\Manual\Development\AutoIt\SCCM Reboot Tool\Logo.jpg", 8, 8, 105, 41) Global $Pic2 = GUICtrlCreatePic("C:\Manual\Development\AutoIt\SCCM Reboot Tool\Logo.jpg", 349, 7, 105, 41) Global $btnMinimize = GUICtrlCreateButton("Minimize", 8, 241, 121, 25) Global $btnRestart = GUICtrlCreateButton("Restart", 335, 241, 121, 25) Global $btnPostpone = GUICtrlCreateButton("Postpone", 195, 242, 73, 25) Global $Label1 = GUICtrlCreateLabel("Restart in Progress", 128, 8, 209, 33) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif") GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) Global $Label1 = GUICtrlCreateLabel("AGCS IT has deployed an update to your computer that requires a" & @CRLF & "reboot. Please restart your computer or postpone to a more convenient" & @CRLF & "time within the specified 8 hour limit. Thanks for your co-operation.", 24, 80, 420, 73, $SS_CENTER) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) ;Global $Input1 = GUICtrlCreateInput("", 160, 184, 145, 21,BitOr($SS_CENTER, $ES_READONLY)) Global $lblTimer = GUICtrlCreateLabel("", 160, 184, 145, 21, BitOR($SS_CENTER, $ES_READONLY)) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) Global $TimeCombo = GUICtrlCreateCombo("10 minutes", 160, 208, 145, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL)) GUICtrlSetData(-1, "20 seconds|30 minutes|1 hour|2 hours|6 hours") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### $timer = TimerInit() $ms = 7200000 While (TimerDiff($timer) < $ms) ;And (GUIGetMsg() <> $Button2) $seconds = TimerDiff($timer) / 1000 $diff = $seconds - ($ms / 1000) ; $minutes = Int($diff / 60) $secondsRem = $diff - ($minutes * 60) ; $minutes = $minutes * -1 $secondsRem = $secondsRem * -1 $time = StringFormat("%02d", $minutes) & ":" & StringFormat("%02d", $secondsRem) ; GUICtrlSetData($lblTimer, $time) $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $btnRestart ConsoleWrite("Restart pressed: Time is UP" & @CRLF) Case $btnPostpone Switch GUICtrlRead($TimeCombo) Case "20 seconds" $ms = 20000 GUICtrlSetData($lblTimer, $time) ConsoleWrite("Time is up 20 seconds") Case "20 minutes" $ms = 1200000 GUICtrlSetData($lblTimer, $time) ConsoleWrite("Time is up 20 minutes") Case "1 hour" $ms = 3600000 GUICtrlSetData($lblTimer, $time) ConsoleWrite("Time is up 1 hour") Case "2 hours" $ms = 7200000 GUICtrlSetData($lblTimer, $time) ConsoleWrite("Time is up 2 hours") Case "6 hours" $ms = 21600000 GUICtrlSetData($lblTimer, $time) ConsoleWrite("Time is up 6 hours") EndSwitch EndSwitch WEnd Edited September 25, 2015 by Kaimberex Link to comment Share on other sites More sharing options...
ViciousXUSMC Posted September 25, 2015 Share Posted September 25, 2015 (edited) Ok here is my shot at it. I made use of Melbas Extended Message Box as it made sense to me and made this easy.This is just the core layout you can change as needed.expandcollapse popup#include <GUIConstantsEx.au3> #include <Constants.au3> #include <StaticConstants.au3> #include <ExtMsgBox.au3> #NoTrayIcon ;Set IT Only Hidden Shortcut for Abort Scheduled Shutdown Control + Alt + Escape HotKeySet("^!{Esc}", "ITOnlyAbort") ;Run Function for First Time Notice() ;Keep Script Open While 1 Sleep(10) WEnd Func Notice() ;Declare Wait Max Static Local $WaitMax = 0 ;Switch for what Wait Options are Avalible Based on 8 Hours Max Switch $WaitMax Case 0 To 360 $vOptions = "Restart Now|Wait 15|Wait 30|Wait 60|Wait 120" Case 361 To 420 $vOptions = "Restart Now|Wait 15|Wait 30|Wait 60" Case 421 To 450 $vOptions = "Restart Now|Wait 15|Wait 30" Case 451 to 465 $vOptions = "Restart Now|Wait 15" Case Else $vOptions = "Restart Now" EndSwitch _ExtMsgBoxSet(1, 2, 0x004080, 0xFFFF00, 10, "Comic Sans MS", 600) $sMsg = "AGCS IT has deployed an update to your computer that requires a reboot." & @CRLF $sMsg &= "Please restart your computer now, or postpone to a more convenient time." & @CRLF & @CRLF $sMsg &= "Thank you for your co-operation." $iRetValue = _ExtMsgBox ($EMB_ICONEXCLAM, $vOptions, "Computer Reboot Notice", $sMsg, 120) _ExtMsgBoxSet(Default) Switch $iRetValue Case 0 ;GUI Closed Shutdownz(600) ;Shutdown in 600 Seconds MsgBox(0, "Reboot Notice", "No Option Chosen, Automatic Reboot Scheduled for 10 Minutes", 30) Case 1 ;First Button Shutdownz(1) Case 2 ;Second Button AdlibRegister("Notice", 60000*15) ;Register Function to run again in 15 Min $WaitMax += 15 ;Add 15 Min to Waitmax Case 3 ;Third Button AdlibRegister("Notice", 60000*30) ;Register Function to run again in 30 Min $WaitMax += 30 ;Add 30 Min to Waitmax Case 4 ;Fourth Button AdlibRegister("Notice", 60000*60) ;Register Function to run again in 60 Min $WaitMax += 60 ;Add 60 Min To Waitmax Case 5 ;Fifth Button AdlibRegister("Notice", 60000*120) ;Register Function to run again in 120 Min $WaitMax += 120 ;Add 120 Min To Waitmax Case 9 ;GUI Timeout Shutdownz(600) ;600 seconds aka 10 Minutes MsgBox(0, "Reboot Notice", "No Option Chosen, Automatic Reboot Scheduled for 10 Minutes", 30) EndSwitch Return $iRetValue EndFunc ; == Func Notice Func Shutdownz($iTime = 1) Run(@ComSpec & " /c shutdown /r /f /t " & $iTime) EndFunc ;== Func Shutdown Func ITOnlyAbort() Run(@ComSpec & " /c shutdown /a") Exit EndFunc ;== Func ITOnlyAbort Edited September 25, 2015 by ViciousXUSMC Link to comment Share on other sites More sharing options...
mikell Posted September 25, 2015 Share Posted September 25, 2015 Please try this (for the concept)May I suggest : when the time choice is done fot postpone then disable the postpone button and the comboexpandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <ComboConstants.au3> #include <GUIConstants.au3> Global $Form1 = GUICreate("Form1", 464, 283, 670, 390, $WS_POPUP) GUISetBkColor(0x004c92) Global $Pic1 = GUICtrlCreatePic("C:\Manual\Development\AutoIt\SCCM Reboot Tool\Logo.jpg", 8, 8, 105, 41) Global $Pic2 = GUICtrlCreatePic("C:\Manual\Development\AutoIt\SCCM Reboot Tool\Logo.jpg", 349, 7, 105, 41) Global $btnMinimize = GUICtrlCreateButton("Minimize", 8, 241, 121, 25) Global $btnRestart = GUICtrlCreateButton("Restart", 335, 241, 121, 25) Global $btnPostpone = GUICtrlCreateButton("Postpone", 195, 242, 73, 25) Global $Label1 = GUICtrlCreateLabel("Restart in Progress", 128, 8, 209, 33) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif") GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) Global $Label1 = GUICtrlCreateLabel("AGCS IT has deployed an update to your computer that requires a" & @CRLF & "reboot. Please restart your computer or postpone to a more convenient" & @CRLF & "time within the specified 8 hour limit. Thanks for your co-operation.", 24, 80, 420, 73, $SS_CENTER) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) ;Global $Input1 = GUICtrlCreateInput("", 160, 184, 145, 21,BitOr($SS_CENTER, $ES_READONLY)) Global $lblTimer = GUICtrlCreateLabel("", 160, 184, 145, 21, BitOR($SS_CENTER, $ES_READONLY)) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) Global $TimeCombo = GUICtrlCreateCombo("", 160, 208, 145, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL)) GUICtrlSetData(-1, "10 minutes|20 seconds|30 minutes|1 hour|2 hours|6 hours", "2 hours") GUISetState(@SW_SHOW) Global $ticks = 7200 ; 2 hours default _Display() AdlibRegister("_Run", 1000) While 1 If $ticks = 0 Then Exit Msgbox(0,"", "restart") $nMsg = GUIGetMsg() Switch $nMsg Case $btnRestart Exit Msgbox(0,"", "restart") Case $TimeCombo _ReadCombo() _Display() Case $btnPostpone _ReadCombo() _Run() AdlibRegister("_Run", 1000) EndSwitch WEnd Func _ReadCombo() Switch GUICtrlRead($TimeCombo) Case "20 seconds" $ticks = 20 Case "10 minutes" $ticks = 600 Case "30 minutes" $ticks = 1800 Case "1 hour" $ticks = 3600 Case "2 hours" $ticks = 7200 Case "6 hours" $ticks = 21600 EndSwitch EndFunc Func _Run() $ticks -= 1 _Display() EndFunc Func _Display() Local $sec, $min, $hr, $time $sec = StringFormat("%02i", Mod($ticks, 60)) $min = StringFormat("%02i", Mod($ticks/60, 60)) $hr = StringFormat("%02i", Mod($ticks/3600, 60)) $time = $hr & ":" & $min & ":" & $sec GUICtrlSetData($lblTimer, $time) EndFunc Link to comment Share on other sites More sharing options...
Kaimberex Posted June 7, 2016 Author Share Posted June 7, 2016 (edited) On 9/25/2015 at 4:16 PM, mikell said: Please try this (for the concept) May I suggest : when the time choice is done fot postpone then disable the postpone button and the combo expandcollapse popup#include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <ComboConstants.au3> #include <GUIConstants.au3> Global $Form1 = GUICreate("Form1", 464, 283, 670, 390, $WS_POPUP) GUISetBkColor(0x004c92) Global $Pic1 = GUICtrlCreatePic("C:\Manual\Development\AutoIt\SCCM Reboot Tool\Logo.jpg", 8, 8, 105, 41) Global $Pic2 = GUICtrlCreatePic("C:\Manual\Development\AutoIt\SCCM Reboot Tool\Logo.jpg", 349, 7, 105, 41) Global $btnMinimize = GUICtrlCreateButton("Minimize", 8, 241, 121, 25) Global $btnRestart = GUICtrlCreateButton("Restart", 335, 241, 121, 25) Global $btnPostpone = GUICtrlCreateButton("Postpone", 195, 242, 73, 25) Global $Label1 = GUICtrlCreateLabel("Restart in Progress", 128, 8, 209, 33) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif") GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) Global $Label1 = GUICtrlCreateLabel("AGCS IT has deployed an update to your computer that requires a" & @CRLF & "reboot. Please restart your computer or postpone to a more convenient" & @CRLF & "time within the specified 8 hour limit. Thanks for your co-operation.", 24, 80, 420, 73, $SS_CENTER) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) ;Global $Input1 = GUICtrlCreateInput("", 160, 184, 145, 21,BitOr($SS_CENTER, $ES_READONLY)) Global $lblTimer = GUICtrlCreateLabel("", 160, 184, 145, 21, BitOR($SS_CENTER, $ES_READONLY)) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) Global $TimeCombo = GUICtrlCreateCombo("", 160, 208, 145, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL)) GUICtrlSetData(-1, "10 minutes|20 seconds|30 minutes|1 hour|2 hours|6 hours", "2 hours") GUISetState(@SW_SHOW) Global $ticks = 7200 ; 2 hours default _Display() AdlibRegister("_Run", 1000) While 1 If $ticks = 0 Then Exit Msgbox(0,"", "restart") $nMsg = GUIGetMsg() Switch $nMsg Case $btnRestart Exit Msgbox(0,"", "restart") Case $TimeCombo _ReadCombo() _Display() Case $btnPostpone _ReadCombo() _Run() AdlibRegister("_Run", 1000) EndSwitch WEnd Func _ReadCombo() Switch GUICtrlRead($TimeCombo) Case "20 seconds" $ticks = 20 Case "10 minutes" $ticks = 600 Case "30 minutes" $ticks = 1800 Case "1 hour" $ticks = 3600 Case "2 hours" $ticks = 7200 Case "6 hours" $ticks = 21600 EndSwitch EndFunc Func _Run() $ticks -= 1 _Display() EndFunc Func _Display() Local $sec, $min, $hr, $time $sec = StringFormat("%02i", Mod($ticks, 60)) $min = StringFormat("%02i", Mod($ticks/60, 60)) $hr = StringFormat("%02i", Mod($ticks/3600, 60)) $time = $hr & ":" & $min & ":" & $sec GUICtrlSetData($lblTimer, $time) EndFunc Thank you for the suggestions. I have used your suggestions because it is a lot cleaner. Here is the finished version should anyone want to use it. expandcollapse popup#NoTrayIcon #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_Res_Description=ShutdownTool #AutoIt3Wrapper_Res_Fileversion=2.1.3.43 #AutoIt3Wrapper_Res_Fileversion_AutoIncrement=p #AutoIt3Wrapper_Res_LegalCopyright=AGCS 2016 ;#AutoIt3Wrapper_Res_SaveSource=y #AutoIt3Wrapper_Res_Language=1033 #AutoIt3Wrapper_Res_requestedExecutionLevel=requireAdministrator ;#AutoIt3Wrapper_Run_Tidy=y ;#Tidy_Parameters=/gd /reel /ri //kv 0 /sf #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** #cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.14.1 Author: Eric Behrens IT - Deskside Services Allianz Global Corporate & Specialty AG redrocker1988@gmail.com Script Function: A tool used with SCCM to display a pop up message to users should a restart, or logoff be required to finish installing a software update. #ce ---------------------------------------------------------------------------- #Region Includes #include <ButtonConstants.au3> #include <File.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <ComboConstants.au3> #include <GUIConstants.au3> #include <_ProcessFunctions.au3> #include <Array.au3> #include <Misc.au3> #EndRegion Includes HotKeySet("^!+e", "_AdminClose") ;allows a technician to terminate the tool before the timer runs out. Hotkey is Ctrl+Alt+Shift+e #Region PreExecution #Region Declare Global Variables Global $GUI_2, $time, $lblMinimizeTimer, $btnRestart, $ticksElapsed, $timeElapsed #EndRegion Declare Global Variables #Region get the owner of the Explorer.exe process so that logging will work for the logged in user when the program is executed as the SYSTEM account. Global $ProcessOwner = _ProcessOpen(ProcessExists("explorer.exe"), 0x20000) Global $LoggedInUser = _ProcessGetOwner($ProcessOwner) #EndRegion get the owner of the Explorer.exe process so that logging will work for the logged in user when the program is executed as the SYSTEM account. #Region Read config.ini file and set parameters for runtime. Global $sTimer = IniRead(@ScriptDir & "\config.ini", "DefaultTimer", "Time", "7200");This reads the .ini file for the desired initial reboot timer. The default will be 2 hours if no timer is set. Global $CustomMessage = IniRead(@ScriptDir & "\config.ini", "CustomMessage", "Message", "Custom Message Here");This reads the specified custom message to be displayed in the restart dialog. Global $LogFileLocation = IniRead(@ScriptDir & "\config.ini", "Logging", "LogDir", "");this sets the log dir for logging. The default is set to C:\Windows\AGCS_SCCM_Reboot_Tool.log Global $ShutDownParmeters = IniRead(@ScriptDir & "\config.ini", "Options", "Action", "Shutdown");the parameters set in the config.ini file tell the function ShutdownComputer() what to do when time runs out or when the restart button is pressed. Global $Logo = IniRead(@ScriptDir & "\config.ini", "Appearance", "Logo", "logo.jpg");Sets the logo Global $PostponeButton = IniRead(@ScriptDir & "\config.ini", "Options", "PostponeButton", "Disable");Disables Postpone button when minimized notification is restored. Global $Logging = IniRead(@ScriptDir & "\config.ini", "Logging", "Logging", "Disable");Enables or disables logging. Global $Process1 = IniRead(@ScriptDir & "\config.ini", "Processes", "1", "") Global $Process2 = IniRead(@ScriptDir & "\config.ini", "Processes", "2", "") Global $Process3 = IniRead(@ScriptDir & "\config.ini", "Processes", "3", "") Global $Process4 = IniRead(@ScriptDir & "\config.ini", "Processes", "4", "") Global $Process5 = IniRead(@ScriptDir & "\config.ini", "Processes", "5", "") Global $Process6 = IniRead(@ScriptDir & "\config.ini", "Processes", "6", "") Global $Process7 = IniRead(@ScriptDir & "\config.ini", "Processes", "7", "") Global $Process8 = IniRead(@ScriptDir & "\config.ini", "Processes", "8", "") Global $Process9 = IniRead(@ScriptDir & "\config.ini", "Processes", "9", "") Global $Process10 = IniRead(@ScriptDir & "\config.ini", "Processes", "10", "") #EndRegion Read config.ini file and set parameters for runtime. #Region Logging If $Logging = "Disabled" Then $LogFileLocation = "" If $Logging = "" Then $LogFileLocation = "" If $Logging = "Enabled" Then If FileExists($LogFileLocation) = 0 Then _FileCreate($LogFileLocation) ;If the log file does not exist create a new log in specified logfile directory. If the file exists log entries will be appended to existing log. _FileWriteLog($LogFileLocation, "ShutdownTool Executed") $fileVersion = FileGetVersion(@ScriptDir & "\ShutdownTool.exe") ;Get the version of the file to display in the log. _FileWriteLog($LogFileLocation, "Author: Eric Behrens - IT - Deskside Services Allianz Global Corporate & Specialty AG") _FileWriteLog($LogFileLocation, "ShutdownTool Version " & $fileVersion) _FileWriteLog($LogFileLocation, "Log file dir = " & $LogFileLocation & ".") _FileWriteLog($LogFileLocation, "Parameters = " & $ShutDownParmeters & ".") If $Process1 = "" Then Else _FileWriteLog($LogFileLocation, "Looking for running process, " & $Process1 & ".") If ProcessExists($Process1) Then _FileWriteLog($LogFileLocation, "Found running process " & $Process1 & "; halting execution until " & $Process1 & " closes.") EndIf If $Process2 = "" Then Else _FileWriteLog($LogFileLocation, "Looking for running process, " & $Process2 & ".") If ProcessExists($Process2) Then _FileWriteLog($LogFileLocation, "Found running process " & $Process2 & "; halting execution until " & $Process2 & " closes.") EndIf If $Process3 = "" Then Else _FileWriteLog($LogFileLocation, "Looking for running process, " & $Process3 & ".") If ProcessExists($Process3) Then _FileWriteLog($LogFileLocation, "Found running process " & $Process3 & "; halting execution until " & $Process3 & " closes.") EndIf If $Process4 = "" Then Else _FileWriteLog($LogFileLocation, "Looking for running process, " & $Process4 & ".") If ProcessExists($Process4) Then _FileWriteLog($LogFileLocation, "Found running process " & $Process4 & "; halting execution until " & $Process4 & " closes.") EndIf If $Process5 = "" Then Else _FileWriteLog($LogFileLocation, "Looking for running process, " & $Process5 & ".") If ProcessExists($Process5) Then _FileWriteLog($LogFileLocation, "Found running process " & $Process5 & "; halting execution until " & $Process5 & " closes.") EndIf If $Process6 = "" Then Else _FileWriteLog($LogFileLocation, "Looking for running process, " & $Process6 & ".") If ProcessExists($Process6) Then _FileWriteLog($LogFileLocation, "Found running process " & $Process6 & "; halting execution until " & $Process6 & " closes.") EndIf If $Process7 = "" Then Else _FileWriteLog($LogFileLocation, "Looking for running process, " & $Process7 & ".") If ProcessExists($Process7) Then _FileWriteLog($LogFileLocation, "Found running process " & $Process7 & "; halting execution until " & $Process7 & " closes.") EndIf If $Process8 = "" Then Else _FileWriteLog($LogFileLocation, "Looking for running process, " & $Process8 & ".") If ProcessExists($Process8) Then _FileWriteLog($LogFileLocation, "Found running process " & $Process8 & "; halting execution until " & $Process8 & " closes.") EndIf If $Process9 = "" Then Else _FileWriteLog($LogFileLocation, "Looking for running process, " & $Process9 & ".") If ProcessExists($Process9) Then _FileWriteLog($LogFileLocation, "Found running process " & $Process9 & "; halting execution until " & $Process9 & " closes.") EndIf If $Process10 = "" Then Else _FileWriteLog($LogFileLocation, "Looking for running process, " & $Process10 & ".") If ProcessExists($Process10) Then _FileWriteLog($LogFileLocation, "Found running process " & $Process10 & "; halting execution until " & $Process10 & " closes.") EndIf EndIf #EndRegion Logging ;wait for the specified processes to close. ProcessWaitClose($Process1) ProcessWaitClose($Process2) ProcessWaitClose($Process3) ProcessWaitClose($Process4) ProcessWaitClose($Process5) ProcessWaitClose($Process6) ProcessWaitClose($Process7) ProcessWaitClose($Process8) ProcessWaitClose($Process9) ProcessWaitClose($Process10) #EndRegion PreExecution #Region Main Popup GUI ;~ GUI1() Global $GUI_1 = GUICreate("ShutdownTool", 464, 283, -1, -1, BitOR($WS_SYSMENU, $WS_POPUP), BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST, $WS_EX_WINDOWEDGE)) GUISetBkColor(0x004c92) Global $Pic1 = GUICtrlCreatePic(@ScriptDir & "\" & $Logo, 8, 8, 105, 41) Global $Pic2 = GUICtrlCreatePic(@ScriptDir & "\" & $Logo, 349, 7, 105, 41) Global $btnMinimize = GUICtrlCreateButton("Minimize", 8, 241, 121, 25) Global $btnRestart = GUICtrlCreateButton("", 335, 241, 121, 25) ;Set the text of the button based off of the specified shutdown parameters Switch $ShutDownParmeters Case $ShutDownParmeters = "Reboot" GUICtrlSetData($btnRestart, "Restart") Case $ShutDownParmeters = "Logoff" GUICtrlSetData($btnRestart, "Logoff") Case $ShutDownParmeters = "Shutdown" GUICtrlSetData($btnRestart, "Shutdown") Case $ShutDownParmeters = "ForceReboot" GUICtrlSetData($btnRestart, "Restart") EndSwitch Global $btnPostpone = GUICtrlCreateButton("Postpone", 195, 242, 73, 25) Global $lblActionInProgress = GUICtrlCreateLabel("", 120, 8, 225, 33, $SS_CENTER) GUICtrlSetFont(-1, 16, 400, 0, "MS Sans Serif") ;~ Global $lblActionInProgress = GUICtrlCreateLabel("", 128, 8, 209, 33) GUICtrlSetColor(-1, 0xFFFFFF) ;~ GUICtrlSetFont(-1, 18, 400, 0, "MS Sans Serif") GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) Switch $ShutDownParmeters Case $ShutDownParmeters = "Reboot" GUICtrlSetData($lblActionInProgress, "Restart in Progress") Case $ShutDownParmeters = "Logoff" GUICtrlSetData($lblActionInProgress, "Logoff in Progress") Case $ShutDownParmeters = "Shutdown" GUICtrlSetData($lblActionInProgress, "Shutdown in Progress") Case $ShutDownParmeters = "ForceReboot" GUICtrlSetData($lblActionInProgress, "Restart in Progress") EndSwitch Global $Label1 = GUICtrlCreateLabel($CustomMessage, 24, 80, 420, 73, $SS_CENTER) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) Global $lblTimer = GUICtrlCreateLabel("", 160, 184, 145, 21, BitOR($SS_CENTER, $ES_READONLY)) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) Global $TimeCombo = GUICtrlCreateCombo("", 160, 208, 145, 25, BitOR($CBS_DROPDOWN, $CBS_AUTOHSCROLL)) GUICtrlSetData(-1, "10 minutes|20 minutes|30 minutes|1 hour|2 hours|6 hours", "2 hours") GUISetState(@SW_SHOW) Global $ticks = $sTimer ; 2 hours default, displayed in seconds Global $ticksElapsed = 0 _Display() AdlibRegister("_Run", 1000) While 1 If $ticks = 0 Then If $Logging = "Enabled" Then _FileWriteLog($LogFileLocation, "Time has expired and " & $ShutDownParmeters & " has been initiated by " & $LoggedInUser & ".") _ProcessCloseHandle($ProcessOwner) _FileWriteLog($LogFileLocation, "Time Elapsed since execution " & $timeElapsed) EndIf ShutdownComputer() EndIf $nMsg = GUIGetMsg() Switch $nMsg Case $btnMinimize If $Logging = "Enabled" Then _FileWriteLog($LogFileLocation, $LoggedInUser & " minimized " & $ShutDownParmeters & " notification.") EndIf GUISetState(@SW_HIDE, $GUI_1) GUI2() Case $btnRestart If $Logging = "Enabled" Then _FileWriteLog($LogFileLocation, $LoggedInUser & " initiated " & $ShutDownParmeters & ".") _FileWriteLog($LogFileLocation, "Time Elapsed since execution " & $timeElapsed) EndIf _ProcessCloseHandle($ProcessOwner) ShutdownComputer() Case $TimeCombo _Display() Case $btnPostpone _ReadCombo() _Run() AdlibRegister("_Run", 1000) ;Minimize to notification area GUISetState(@SW_HIDE, $GUI_1) GUI2() EndSwitch WEnd #EndRegion Main Popup GUI #Region Functions Func _AdminClose() ;This is an administrative close function to stop the tool from launching. This is a technician only hotkey and must not be published to end users. If $Logging = "Enabled" Then _FileWriteLog($LogFileLocation, "Time Elapsed since execution " & $timeElapsed) _FileWriteLog($LogFileLocation, $ShutDownParmeters & " terminated by AdminClose hotkey.") EndIf Exit EndFunc ;==>_AdminClose Func _Display() Local $sec, $min, $hr, $time $sec = StringFormat("%02i", Mod($ticks, 60)) $min = StringFormat("%02i", Mod($ticks / 60, 60)) $hr = StringFormat("%02i", Mod($ticks / 3600, 60)) $time = $hr & ":" & $min & ":" & $sec GUICtrlSetData($lblTimer, $time) GUICtrlSetData($lblMinimizeTimer, $time) EndFunc ;==>_Display Func _ReadCombo() Switch GUICtrlRead($TimeCombo) Case "20 minutes" If $Logging = "Enabled" Then FileOpen($LogFileLocation, 9) _FileWriteLog($LogFileLocation, $ShutDownParmeters & " was postponed for 20 minutes by " & $LoggedInUser & ".") EndIf $ticks = 1200 + ($sTimer - $ticksElapsed) Case "10 minutes" If $Logging = "Enabled" Then FileOpen($LogFileLocation, 9) _FileWriteLog($LogFileLocation, $ShutDownParmeters & " was postponed for 10 minutes by " & $LoggedInUser & ".") EndIf $ticks = 600 + ($sTimer - $ticksElapsed) Case "30 minutes" If $Logging = "Enabled" Then FileOpen($LogFileLocation, 9) _FileWriteLog($LogFileLocation, $ShutDownParmeters & " was postponed for 30 minutes by " & $LoggedInUser & ".") EndIf $ticks = 1800 + ($sTimer - $ticksElapsed) Case "1 hour" If $Logging = "Enabled" Then FileOpen($LogFileLocation, 9) _FileWriteLog($LogFileLocation, $ShutDownParmeters & " postponed for 1 hour by " & $LoggedInUser & ".") EndIf $ticks = 3600 + ($sTimer - $ticksElapsed) Case "2 hours" If $Logging = "Enabled" Then FileOpen($LogFileLocation, 9) _FileWriteLog($LogFileLocation, $ShutDownParmeters & " was postponed for 2 hours by " & $LoggedInUser & ".") EndIf $ticks = 7200 + ($sTimer - $ticksElapsed) Case "6 hours" If $Logging = "Enabled" Then FileOpen($LogFileLocation, 9) _FileWriteLog($LogFileLocation, $ShutDownParmeters & " was postponed for 6 hours by " & $LoggedInUser & ".") EndIf $ticks = 21600 + ($sTimer - $ticksElapsed) EndSwitch EndFunc ;==>_ReadCombo Func _Run() $ticks -= 1 _Display() $ticksElapsed += 1 _TimeElapsed() EndFunc ;==>_Run Func _TimeElapsed() Local $sec, $min, $hr, $time $sec = StringFormat("%02i", Mod($ticksElapsed, 60)) $min = StringFormat("%02i", Mod($ticksElapsed / 60, 60)) $hr = StringFormat("%02i", Mod($ticksElapsed / 3600, 60)) $timeElapsed = $hr & ":" & $min & ":" & $sec EndFunc ;==>_TimeElapsed Func GUI2() $aTaskbar = WinGetPos("[CLASS:Shell_TrayWnd]", "") $GUI_2 = GUICreate("", 160, 54, @DesktopWidth, @DesktopHeight, BitOR($WS_SYSMENU, $WS_POPUP), $WS_EX_TOPMOST) GUISetBkColor(0x004c92) $Text = GUICtrlCreateLabel("Restart in Progress", 8, 8, 138, 20, $SS_CENTER) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) Switch $ShutDownParmeters Case $ShutDownParmeters = "Reboot" GUICtrlSetData($Text, "Restart in Progress") Case $ShutDownParmeters = "Logoff" GUICtrlSetData($Text, "Logoff in Progress") Case $ShutDownParmeters = "Shutdown" GUICtrlSetData($Text, "Shutdown in Progress") Case $ShutDownParmeters = "ForceReboot" GUICtrlSetData($Text, "Restart in Progress") EndSwitch $lblMinimizeTimer = GUICtrlCreateLabel("", 8, 32, 138, 17, $SS_CENTER) GUICtrlSetColor(-1, 0xFFFFFF) GUICtrlSetBkColor(-1, $GUI_BKCOLOR_TRANSPARENT) $aWin = WinGetPos($GUI_2) WinMove($GUI_2, "", @DesktopWidth - $aWin[2] - 4, @DesktopHeight - $aWin[3] - $aTaskbar[3] - 4) GUISetState(@SW_SHOW) While 1 If $ticks = 0 Then If $Logging = "Enabled" Then _FileWriteLog($LogFileLocation, "Time has expired and " & $ShutDownParmeters & " has been initiated by " & $LoggedInUser & ".") _FileWriteLog($LogFileLocation, "Time Elapsed since execution " & $timeElapsed) EndIf ShutdownComputer() EndIf $nMsg = GUIGetMsg() Switch $nMsg Case $Text, $lblMinimizeTimer ;User clicks anywhere on the text GUISetState(@SW_HIDE, $GUI_2) GUISetState(@SW_SHOW, $GUI_1) Switch $PostponeButton Case "Disable" GUICtrlSetState($btnPostpone, $GUI_Disable) GUICtrlSetState($TimeCombo, $GUI_Disable) Case "Enable" EndSwitch ExitLoop EndSwitch WEnd EndFunc ;==>GUI2 Func ShutdownComputer() _ProcessCloseHandle($ProcessOwner) ;~ The shutdown code is a combination of the following values: ;~ $SD_LOGOFF (0) = Logoff ;~ $SD_SHUTDOWN (1) = Shutdown ;~ $SD_REBOOT (2) = Reboot ;~ $SD_FORCE (4) = Force ;~ $SD_POWERDOWN (8) = Power down ;~ $SD_FORCEHUNG (16) = Force if hung ;~ $SD_STANDBY (32) = Standby ;~ $SD_HIBERNATE (64) = Hibernate Switch $ShutDownParmeters Case $ShutDownParmeters = "Reboot" Shutdown(2) Case $ShutDownParmeters = "Logoff" Shutdown(0) Case $ShutDownParmeters = "Shutdown" Shutdown(1) Case $ShutDownParmeters = "ForceReboot" Shutdown(6) EndSwitch EndFunc ;==>ShutdownComputer #EndRegion Functions expandcollapse popupYou do not need to run parameters with ShutdownTool.exe. All Parameters are configured in config.ini. Config.ini MUST be placed in the same folder as ShutdownTool.exe. Admin Hotkey Ctrl+Alt+Shift+e There is an AdminKey hotkey to terminate the tool should a technician need to close the tool before the timer runs out. This is an administrative close function to stop the tool from executing the shutdown sequence. This is a technician only hotkey and must not be published to end users. CONFIG.INI settings [DefaultTimer] This will set the timer that displays when initially launching the tool. The default timer is set to two hours. The time is set using seconds. Two hours is equal to 7200 seconds. The user will be able to postpone the timer for 10 minutes, 20 minutes, 30 minutes, 1 hour, 2 hours, 4 hours, or 6 hours. The postponed time will be added to the initial timer. [Custom Message] This section displays a custom message that will be displayed on the popup. If the computer requires a logoff instead of a reboot you must specifiy that in the message. If it requires a reboot you must specify that in the message. [Appearance] There are placeholders for two logos. One in the upper right hand corner and upper left hand corner. The logo files must be images in .bmp or .jpg format and cannot exceed 237x88 pixels. Place the image in the same directory as ShutdownTool.exe and config.ini [Processes] The tool will not launch if there are running processes that are defined in this section. There are placeholders for up to 10 processes. You must include the process name listed in task manager. For instance WINWORD.exe. Once the processes are closed the tool will pop up with the default timer. [Logging] This section tells the tool where the log file location will be. This must be a full path and cannot contain any spaces. The default location is C:\Windows\ShutdownTool.log. The log entries will append to the end of the log file with date and time timestamps. If you wish to disable Logging then make sure Logging=Disabled. If Logging=Enabled then LogDir must be specified. [Options] This section tells the tool what to do when the timer runs out, or when the User clicks the Restart, Shutdown, or Logoff button. Logoff - will log the user off immediately. Shutdown - Will shutdown the computer immediately. Reboot - will reboot the computer if there are no active applications. ForceReboot - will force the reboot. ForceReboot is recommended if a reboot is required as it will not hang and the reboot will be enforced when the timer runs out. PostponeButton - This will enable or disable the ability to postpone the timer further when the minimized notification is restored. Disallowing the user to postpone more than one time. Default vaule is disable. ShutdownTool.zip Edited June 7, 2016 by Kaimberex 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