Ruud0209 Posted July 26, 2010 Share Posted July 26, 2010 I'm looking for a way to prevent a script from being ended/closed with Alt-F4 or Taskmgr like a system process or a windows service. They give "access denied" messages when you try to kill them. Can the same be done in AutoIT ? kind regards, Ruud Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 26, 2010 Moderators Share Posted July 26, 2010 Ruud0209, First, and very important, question - why do you want to prevent your scripts being terminated in this way? 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...
trancexx Posted July 26, 2010 Share Posted July 26, 2010 (edited) Question should have been: "Can this be done at all?". If put that way and accompanied with some code (language is irrelevant) or even idea about the code (google), it would be a legit programmer's question that could produce sensible discussion and who knows, maybe yield a solution for you. This way you'll get nothing.What Melba23 is implying is that you (Ruud0209) have unclean thoughts. This suggestion seems to be correct primarily because of your rhetoric. It's poor. Says a lot about you.It should also be said that when that really is the case one shouldn't be helped on these forums. Edited July 26, 2010 by trancexx ♡♡♡ . eMyvnE Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 26, 2010 Moderators Share Posted July 26, 2010 trancexx,What Melba23 is implying is that you (Ruud0209) have unclean thoughtsWell, that is one way to put it. Although I would stress that I am purely concerned about the limpidity of his coding intentions - the rest of his thoughts are, of course, none of my business. 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...
Developers Jos Posted July 26, 2010 Developers Share Posted July 26, 2010 (edited) Ruud, What is it you want to do that cannot be done by standard Windows security? When a user has limited right to the PC, it will be hard to kill a process that runs under admin credentials... Questions like this always triggers all kind of alarmbells since it could be used for malicious purposes. Jos Edited July 26, 2010 by Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
DarkAngel Posted July 26, 2010 Share Posted July 26, 2010 i hope the u dun have a malicious intent. Anyways u can see the _procwatch() udf . Search in the forums. Well u wont have a system attribute to ur exe but maybe this can help u. Link to comment Share on other sites More sharing options...
Ruud0209 Posted July 27, 2010 Author Share Posted July 27, 2010 (edited) I'm sorry,I suppose I should've added my code right away. Basicly what i'm trying to accomplish is the following: We, the company I work for that is, want to have our users reboot their PC's at least once every six day to ensure they get the latest version of software and group policy's etc. deployed. We have a thing called "workspace manager" and this runs when a user logs on. With it we can run MSI's, run scripts,programs or batch files (with elevated credentials if needed), create shortcuts, basicly anything we want. I also want to use it to run this script when compiled so it notify's the user if his/hers PC has been running for more than 6 days. With some code I found in the forums I've managed to come up with what you see below. This works, up to the point that if a user does not want to be bothered by it, he can start task manager op activate the gui and kill it. so far for my "unclean" thougts altough I get why one would or could think that... I've attached the source plus the includes (i use one or two older ones) to this post. thank you for any of your thoughts or ideas to improve this... kind regards, Ruud BTW : Can anybody give me a hint on how to prevent a script from being run twice (so that it checks if already running and if so then exits ?) expandcollapse popup#NoTrayIcon #Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_icon=..\icons\shell32_329.ico #AutoIt3Wrapper_outfile=UptimeCalc.exe #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ;#NoTrayIcon #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <SendMessage.au3> #include <Date.au3> #include <Constants.au3> #include <MsgBoxEx.au3> AutoItSetOption("TrayMenuMode", 9) ; Default tray menu items (Script Paused/Exit) will not be shown. $guiitem = TrayCreateItem("Show All") $dayssitem = TrayCreateItem("Power") TrayCreateItem("") $rebootitem = TrayCreateItem("Reboot") TraySetState() Global Const $SC_DRAGMOVE = 0xF012 Local $iHours, $iMins, $iSecs HotKeySet("^!X", "_exit") HotKeySet("^!x", "_exit") HotKeySet("^{F4}", "_min") Func _Min() GUISetState(@SW_HIDE) EndFunc ;==>_min Local $tMsg, $tItem1, $iCurrDays Func _exit() Exit EndFunc ;==>_exit $frmMain = GUICreate("System :: Uptime", 300, 200, @DesktopWidth / 2 - 145, @DesktopHeight / 2 - 160, BitOR($WS_POPUPWINDOW, $WS_BORDER), $WS_EX_TOPMOST) ;$frmMain = GUICreate("System :: Uptime", 290, 166, @DesktopWidth / 2 - 145 , @DesktopHeight / 2 - 160, $WS_BORDER, $WS_EX_TOPMOST) ;UISetBkColor(0x000000) $lblDays = GUICtrlCreateLabel("00", 8, 8, 15, 15) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") ;UICtrlSetColor(-1, 0x00FF00) $lblSep1 = GUICtrlCreateLabel(":", 23, 8, 10, 15) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") ;GUICtrlSetColor(-1, 0x00FF00) $lblHours = GUICtrlCreateLabel("00", 28, 8, 15, 15) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") ;UICtrlSetColor(-1, 0x00FF00) $lblSep2 = GUICtrlCreateLabel(":", 42, 8, 10, 15) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") ;GUICtrlSetColor(-1, 0x00FF00) $lblMinutes = GUICtrlCreateLabel("00", 47, 8, 15, 15) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") ;GUICtrlSetColor(-1, 0x00FF00) $lblSep3 = GUICtrlCreateLabel(":", 62, 8, 10, 15) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") ;GUICtrlSetColor(-1, 0x00FF00) $lblSeconds = GUICtrlCreateLabel("00", 68, 8, 15, 15) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") ;GUICtrlSetColor(-1, 0x00FF00) $about = GUICtrlCreateButton("About", 245, 10, 45, 25, $BS_FLAT) $btnWait = GUICtrlCreateButton("Reboot later ...", 10, 130, 280, 25, $BS_FLAT) $Reboot = GUICtrlCreateButton("Reboot Now !", 10, 165, 280, 25, $BS_FLAT) $label4 = GUICtrlCreateLabel("Your computer has been running for more than 0 days" & @CRLF & "", 8, 45, 300, 26) $label1 = GUICtrlCreateLabel("If your computer has been running for more than 6 days" & @CRLF & "you can postpone the reboot only 3 times.(1 hour each time)", 8, 75, 300, 26) $label2 = GUICtrlCreateLabel("", 8, 105, 200, 12) $iCurrSecs = 0 $iCurrMins = 0 $iCurrHrs = 0 $iCurrDays = 0 $iPostPone = 0 $iloop = 0 Dim $iDays, $openfromtray While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_PRIMARYDOWN _SendMessage($frmMain, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0) Case $GUI_EVENT_CLOSE Exit Case $Reboot GUISetState(@SW_HIDE) $ls = "The computer will reboot in <##> seconds. Click OK for an immediate reboot." $liRtnVal = _MsgBoxEx(1 + 48 + 1024, "Reboot", $ls, 30) Select Case $liRtnVal = 1 ;OK Shutdown(3) Case $liRtnVal = -1 ;OK Shutdown(3) Case $liRtnVal = 2 ;Cancel EndSelect Case $btnWait GUISetState(@SW_HIDE) If $iDays >= 6 Then $iPostPone = $iPostPone + 1 Else $iPostPone = 0 EndIf If $iPostPone <> 0 Then GUICtrlSetData($label2, "You have postponed the reboot " & $iPostPone & " time(s)") GUICtrlSetState($Reboot, BitOR($GUI_DEFBUTTON, $GUI_FOCUS)) EndIf If $iPostPone >= 3 Then GUICtrlSetState($btnWait, $GUI_DISABLE) EndIf If $openfromtray = 1 Then $openfromtray = 0 Else Sleep(3600000) EndIf Case $about GUISetState(@SW_HIDE) GUISetState(@SW_DISABLE) $iMsgBoxAnswer = MsgBox(64, "About :", "This program enforces regular reboots for user PC's to ensure the latest updates en software versions are deployed." & @CRLF & @CRLF & "Contact the ICT Helpdesk Boxmeer for support." & @CRLF & @CRLF, 30) GUISetStyle(BitOR($WS_POPUPWINDOW, $WS_BORDER), $WS_EX_TOPMOST) GUISetState(@SW_ENABLE) GUISetState(@SW_SHOW) WinActivate("System :: Uptime") Case $GUI_EVENT_CLOSE GUISetState(@SW_HIDE) EndSwitch $GTC = DllCall("kernel32.dll", "long", "GetTickCount") $TSB = $GTC[0] _TicksToTime($TSB, $iHours, $iMins, $iSecs) $iDays = Int($iHours / 24) $iHours = $iHours - ($iDays * 24) If $iSecs <> $iCurrSecs Then If $iDays <> $iCurrDays Then GUICtrlSetData($lblDays, StringFormat("%02i", $iDays)) If $iDays >= 6 Then GUICtrlSetData($label4, "Your computer has been running for more than " & $iDays & " days" & @CRLF & "and requires a reboot.") Else GUICtrlSetData($label4, "Your computer has been running for more than " & $iDays & " days" & @CRLF & "") EndIf $iCurrDays = $iDays EndIf If $iCurrHrs <> $iHours Then GUICtrlSetData($lblHours, StringFormat("%02i", $iHours)) $iCurrHrs = $iHours EndIf If $iCurrMins <> $iMins Then GUICtrlSetData($lblMinutes, StringFormat("%02i", $iMins)) $iCurrMins = $iMins EndIf GUICtrlSetData($lblSeconds, StringFormat("%02i", $iSecs)) $iCurrSecs = $iSecs EndIf If $iDays >= 6 Then GUISetState(@SW_SHOW) EndIf WinMove("System :: Uptime", "", @DesktopWidth / 2 - 145, @DesktopHeight / 2 - 160) $msg = TrayGetMsg() TrayItemSetText($dayssitem, "Your computer has been running for " & $iDays & " days.") TrayItemSetState($rebootitem, 4) TrayItemSetState($dayssitem, 4) TrayItemSetState($guiitem, 4) TraySetToolTip("Your computer has been running for " & $iDays & " days.") Select Case $msg = $rebootitem GUISetState(@SW_HIDE) $ls = "The computer will reboot in <##> seconds. Click OK for an immediate reboot." $liRtnVal = _MsgBoxEx(1 + 48 + 1024, "Reboot", $ls, 30) Select Case $liRtnVal = 1 ;OK Shutdown(3) Case $liRtnVal = -1 ;OK Shutdown(3) Case $liRtnVal = 2 ;Cancel EndSelect Case $msg = $dayssitem ; do nothing Case $msg = $guiitem GUISetState(@SW_ENABLE) GUISetState(@SW_SHOW) $openfromtray = 1 EndSelect WEnd Edited July 27, 2010 by Ruud0209 Link to comment Share on other sites More sharing options...
Ruud0209 Posted July 27, 2010 Author Share Posted July 27, 2010 (edited) Ruud,What is it you want to do that cannot be done by standard Windows security?When a user has limited right to the PC, it will be hard to kill a process that runs under admin credentials...Questions like this always triggers all kind of alarmbells since it could be used for malicious purposes.JosHi,Tanks for your input.I've realized just now that the user I tested with (wich I thought was a regular account) was actually a local admin and had there fore right to close the program. Removing this account from the administrators and testing again proved succesfull for Task Manager but when the gui is opened it can still be killed with Alt-F4....regards,Ruud Sas Edited July 27, 2010 by Ruud0209 Link to comment Share on other sites More sharing options...
Xenobiologist Posted July 27, 2010 Share Posted July 27, 2010 (edited) Hi, try this. Code is 111 Free your PC with F9 and then again 111 MegaMegaBlock.zip Edited July 27, 2010 by Xenobiologist Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
Ruud0209 Posted July 27, 2010 Author Share Posted July 27, 2010 Question should have been: "Can this be done at all?". If put that way and accompanied with some code (language is irrelevant) or even idea about the code (google), it would be a legit programmer's question that could produce sensible discussion and who knows, maybe yield a solution for you. This way you'll get nothing.What Melba23 is implying is that you (Ruud0209) have unclean thoughts. This suggestion seems to be correct primarily because of your rhetoric. It's poor. Says a lot about you.It should also be said that when that really is the case one shouldn't be helped on these forums.Well excuse me sir if my rethoric is poor but equaly so is your judge of character. I even had to look up the word rhethoric but then again English is not my native tongue.I'll be sure to add my code, if any, and intentions in future posts. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 27, 2010 Moderators Share Posted July 27, 2010 Ruud0209,Can anybody give me a hint on how to prevent a script from being run twice (so that it checks if already running and if so then exits ?)Look at _Singleton in the Help file. And apologies for appearing mistrustful initially - the problem is that we are so often proved right. 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...
Ruud0209 Posted July 27, 2010 Author Share Posted July 27, 2010 Hi,try this. Code is 111Free your PC with F9 and then again 111MegaThanks,I'll try this tomorow if I can find the time...regards,Ruud Link to comment Share on other sites More sharing options...
Ruud0209 Posted July 27, 2010 Author Share Posted July 27, 2010 Ruud0209,Look at _Singleton in the Help file. And apologies for appearing mistrustful initially - the problem is that we are so often proved right. M23Thank you and no harm done. I'll give this a try tomorow ...regards,Ruud Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 27, 2010 Moderators Share Posted July 27, 2010 Ruud0209,When you reply please use the "Add Reply" button at the top and bottom of the page rather then the "Reply" button in the post itself. That way you do not get the contents of the previous post quoted in your reply and the whole thread becomes easier to read. 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...
JohnOne Posted July 27, 2010 Share Posted July 27, 2010 Pretty good that MegaBlock, I was however able to break out of it without using F9, but that was the uncompiled script. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Xenobiologist Posted July 27, 2010 Share Posted July 27, 2010 Pretty good that MegaBlock, I was however able to break out of it without using F9, but that was the uncompiled script.What did you do? CTRL+ALT+F9 is also a hotkey for ending the script. (It is the emergency exit ) Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
JohnOne Posted July 27, 2010 Share Posted July 27, 2010 Ctrl alt del to start taskman navigate to the process, use enter key to end it on confirmation window use shift and space The mouse is still loced ctrl alt delete again start taskman job done AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
Ruud0209 Posted July 27, 2010 Author Share Posted July 27, 2010 Melba23, Good point, will do Link to comment Share on other sites More sharing options...
Developers Jos Posted July 27, 2010 Developers Share Posted July 27, 2010 Well excuse me sir if my rethoric is poor .....Don't mind her, you'll get used to it .... of misschien toch niet SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Ruud0209 Posted July 28, 2010 Author Share Posted July 28, 2010 Hello all, thank you all for your input. I've cleaned up the code a little and made some minor improvements. I could not get the Megablock do exactly what I want so I came up with a different solution where the GUI just starts a new instance and then exits. It's all in the code below for those of you who might be interested... regards, Ruud expandcollapse popup#NoTrayIcon #region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_icon=..\icons\shell32_329.ico #AutoIt3Wrapper_outfile=UptimeCalc.exe #AutoIt3Wrapper_Res_Comment=Uptime Calculator, Watches uptime of a PC and warns user to reboot their PC after 6 days. #AutoIt3Wrapper_Res_Description=Uptime Calculator, Watches uptime of a PC and warns user to reboot their PC after 6 days. #AutoIt3Wrapper_Res_Fileversion=1.2.3.4 #endregion ;**** Directives created by AutoIt3Wrapper_GUI **** #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #include <SendMessage.au3> #include <Date.au3> #include <Constants.au3> #include <MsgBoxEx.au3> #include <Misc.au3> ; Checks if it is already running and exits if so. If _Singleton("UptimeCalc", 0) = 0 Then Exit ;Define Hotkeys HotKeySet("^+!X", "_exit") ; Ctrl-Shift-Alt-X to exit HotKeySet("^+!x", "_exit") ; Ctrl-Shift-Alt-x to exit AutoItSetOption("TrayMenuMode", 9) ; Default tray menu items (Script Paused/Exit) will not be shown.\ ; define trayicon menu options $guiitem = TrayCreateItem("Show All") $dayssitem = TrayCreateItem("Power") $aboutitem = TrayCreateItem("About") TrayCreateItem("") $rebootitem = TrayCreateItem("Reboot") TraySetState() ;Define variables Global Const $SC_DRAGMOVE = 0xF012 Local $iHours, $iMins, $iSecs Local $tMsg, $tItem1, $iCurrDays Dim $iDays, $openfromtray $iCurrSecs = 0 $iCurrMins = 0 $iCurrHrs = 0 $iCurrDays = 0 $iPostPone = IniRead(@TempDir & "\" & @ScriptName & ".INI", "General", "Postponed", "0") $iloop = 0 ;Function _exit exits the script. Func _exit() Exit EndFunc ;==>_exit ;Define the GUI $frmMain = GUICreate("System :: Uptime", 300, 200, @DesktopWidth / 2 - 145, @DesktopHeight / 2 - 160, BitOR($WS_POPUP, $WS_BORDER)) $lblDays = GUICtrlCreateLabel("00", 8, 8, 15, 15) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") $lblSep1 = GUICtrlCreateLabel(":", 23, 8, 10, 15) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") $lblHours = GUICtrlCreateLabel("00", 28, 8, 15, 15) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") $lblSep2 = GUICtrlCreateLabel(":", 42, 8, 10, 15) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") $lblMinutes = GUICtrlCreateLabel("00", 47, 8, 15, 15) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") $lblSep3 = GUICtrlCreateLabel(":", 62, 8, 10, 15) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") $lblSeconds = GUICtrlCreateLabel("00", 68, 8, 15, 15) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") $about = GUICtrlCreateButton("About", 245, 10, 45, 25, $BS_FLAT) $btnWait = GUICtrlCreateButton("Reboot later ...", 10, 130, 280, 25, $BS_FLAT) $Reboot = GUICtrlCreateButton("Reboot Now !", 10, 165, 280, 25, $BS_FLAT) $label4 = GUICtrlCreateLabel("Your computer has been running for more than 0 days" & @CRLF & "", 8, 45, 300, 26) $label1 = GUICtrlCreateLabel("If your computer has been running for more than 6 days" & @CRLF & "you can postpone the reboot only 3 times.(1 hour each time)", 8, 75, 300, 26) $label2 = GUICtrlCreateLabel("", 8, 105, 200, 12) ; Check the GUI for input While 1 ; Move to center if moved WinMove("System :: Uptime", "", @DesktopWidth / 2 - 145, @DesktopHeight / 2 - 160) WinSetOnTop("System :: Uptime", "", 1) $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_PRIMARYDOWN _SendMessage($frmMain, $WM_SYSCOMMAND, $SC_DRAGMOVE, 0) Case $GUI_EVENT_CLOSE IniWrite(@TempDir & "\" & @ScriptName & ".ini", "General", "Postponed", $iPostPone) For $i = 255 To 0 Step -2 WinSetTrans("System :: Uptime", "", $i) Next GUISetState(@SW_HIDE) Run(@ScriptFullPath) Exit Case $Reboot For $i = 255 To 0 Step -2 WinSetTrans("System :: Uptime", "", $i) Next GUISetState(@SW_HIDE) $ls = "The computer will reboot in <##> seconds. Click OK for an immediate reboot." $liRtnVal = _MsgBoxEx(1 + 48 + 1024, "Reboot", $ls, 30) Select Case $liRtnVal = 1 ;OK FileDelete(@TempDir & "\" & @ScriptDir & ".ini") Shutdown(3) Case $liRtnVal = -1 ;OK FileDelete(@TempDir & "\" & @ScriptDir & ".ini") Shutdown(3) Case $liRtnVal = 2 ;Cancel EndSelect Case $btnWait For $i = 255 To 0 Step -2 WinSetTrans("System :: Uptime", "", $i) Next GUISetState(@SW_HIDE) If $iDays >= 6 Then $iPostPone = $iPostPone + 1 Else $iPostPone = 0 EndIf If $iPostPone <> 0 Then GUICtrlSetData($label2, "You have postponed the reboot " & $iPostPone & " time(s)") GUICtrlSetState($Reboot, BitOR($GUI_DEFBUTTON, $GUI_FOCUS)) EndIf If $iPostPone >= 3 Then GUICtrlSetState($btnWait, $GUI_DISABLE) EndIf If $openfromtray = 1 Then $openfromtray = 0 Else TraySetToolTip("Sleeping : Your computer has been running for " & $iDays & " days.") Sleep(3600000) EndIf Case $about ;GUISetState(@SW_HIDE) GUISetState(@SW_DISABLE) WinSetOnTop("System :: Uptime", "", 0) If FileExists(@WindowsDir & "\Media\chord.wav") Then SoundPlay(@WindowsDir & "\Media\chord.wav") $ls = "This program enforces regular reboots for user PC's to ensure the latest updates en software versions are deployed." & @CRLF & @CRLF & "Contact the ICT Helpdesk Boxmeer for support." & @CRLF & @CRLF $liRtnVal = _MsgBoxEx(0 + 64 + 1024, "about:", $ls, 30) GUISetState(@SW_ENABLE) WinActivate("System :: Uptime") WinSetOnTop("System :: Uptime", "", 1) EndSwitch ; Do the time calculation stuff $GTC = DllCall("kernel32.dll", "long", "GetTickCount") $TSB = $GTC[0] _TicksToTime($TSB, $iHours, $iMins, $iSecs) $iDays = Int($iHours / 24) $iHours = $iHours - ($iDays * 24) If $iSecs <> $iCurrSecs Then If $iDays <> $iCurrDays Then GUICtrlSetData($lblDays, StringFormat("%02i", $iDays)) If $iDays >= 6 Then GUICtrlSetData($label4, "Your computer has been running for more than " & $iDays & " days" & @CRLF & "and requires a reboot.") Else GUICtrlSetData($label4, "Your computer has been running for more than " & $iDays & " days" & @CRLF & "") EndIf $iCurrDays = $iDays EndIf If $iCurrHrs <> $iHours Then GUICtrlSetData($lblHours, StringFormat("%02i", $iHours)) $iCurrHrs = $iHours EndIf If $iCurrMins <> $iMins Then GUICtrlSetData($lblMinutes, StringFormat("%02i", $iMins)) $iCurrMins = $iMins EndIf GUICtrlSetData($lblSeconds, StringFormat("%02i", $iSecs)) $iCurrSecs = $iSecs EndIf If $iDays >= 6 Then WinSetTrans("System :: Uptime", "", 0) GUISetState(@SW_SHOW) For $i = 0 To 255 Step 2 WinSetTrans("System :: Uptime", "", $i) Next EndIf ; Check the trayicon menu for input $msg = TrayGetMsg() TrayItemSetText($dayssitem, "Your computer has been running for " & $iDays & " days.") TrayItemSetState($rebootitem, 4) TrayItemSetState($dayssitem, 4) TrayItemSetState($aboutitem, 4) TrayItemSetState($guiitem, 4) TraySetToolTip("Your computer has been running for " & $iDays & " days.") Select Case $msg = $rebootitem GUISetState(@SW_HIDE) If FileExists(@WindowsDir & "\Media\chord.wav") Then SoundPlay(@WindowsDir & "\Media\chord.wav") $ls = "The computer will reboot in <##> seconds. Click OK for an immediate reboot." $liRtnVal = _MsgBoxEx(1 + 48 + 1024, "Reboot", $ls, 30) Select Case $liRtnVal = 1 ;OK Shutdown(3) Case $liRtnVal = -1 ;OK Shutdown(3) Case $liRtnVal = 2 ;Cancel EndSelect Case $msg = $aboutitem ;GUISetState(@SW_HIDE) GUISetState(@SW_DISABLE) WinSetOnTop("System :: Uptime", "", 0) If FileExists(@WindowsDir & "\Media\chord.wav") Then SoundPlay(@WindowsDir & "\Media\chord.wav") $ls = "This program enforces regular reboots for user PC's to ensure the latest updates en software versions are deployed." & @CRLF & @CRLF & "Contact the ICT Helpdesk Boxmeer for support." & @CRLF & @CRLF $liRtnVal = _MsgBoxEx(0 + 64 + 1024, "about:", $ls, 30) GUISetState(@SW_ENABLE) WinActivate("System :: Uptime") WinSetOnTop("System :: Uptime", "", 1) Case $msg = $dayssitem ; do nothing Case $msg = $guiitem GUISetState(@SW_ENABLE) WinSetTrans("System :: Uptime", "", 0) GUISetState(@SW_SHOW) For $i = 0 To 255 Step 2 WinSetTrans("System :: Uptime", "", $i) Next $openfromtray = 1 EndSelect WEndsystemuptime.au3 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