Jump to content

Prevent script from being killed by Taskmanager or Alt-F4


Recommended Posts

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

  • Moderators

Ruud0209,

First, and very important, question - why do you want to prevent your scripts being terminated in this way? :blink:

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

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 by trancexx

♡♡♡

.

eMyvnE

Link to comment
Share on other sites

  • Moderators

trancexx,

What Melba23 is implying is that you (Ruud0209) have unclean thoughts

Well, 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. :blink:

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

  • Developers

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

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 :blink: 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 ?)

#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 by Ruud0209
Link to comment
Share on other sites

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

Hi,

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 by Ruud0209
Link to comment
Share on other sites

Hi,

try this. Code is 111

Free your PC with F9 and then again 111

Mega

MegaBlock.zip

Edited 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

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

  • Moderators

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

And apologies for appearing mistrustful initially - the problem is that we are so often proved right. ;)

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

Ruud0209,

Look at _Singleton in the Help file. :blink:

And apologies for appearing mistrustful initially - the problem is that we are so often proved right. :P

M23

Thank you and no harm done. ;)

I'll give this a try tomorow ...

regards,

Ruud

Link to comment
Share on other sites

  • Moderators

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

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

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 :blink: )

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

  • Developers

Well excuse me sir if my rethoric is poor .....

Don't mind her, you'll get used to it .... of misschien toch niet :blink:

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

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

#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
WEnd

systemuptime.au3

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