Jump to content

Recommended Posts

Posted

Hi, How can I check if the system is idle for 15mins?

also, i got this ie.au3 working very nice :whistle: but is it possible to find the last 2 url's in a website and click it?

Posted

i am total nub, but i made this script and i have running on my pcs. it checks if it has been inactive for 5 minutes, if so, it will shutdown. thought i might help. like i said before, i am new to programming,my coding sux.

;================================================================
;======================= iNACTIVITy ============================
;'_shutdown author : AutoItKing
;'_GuiRoundCorners author: unknown
;================================================================
#include-once
#include <Constants.au3>
#include <GUIConstants.au3>
#include <Date.au3>
#include <Misc.au3>
Opt("GUIOnEventMode", 1)
AutoItWinSetTitle("")
Opt("WinTitleMatchMode", 4)
AutoItSetOption("TrayIconDebug", 0)
AutoItSetOption("TrayAutoPause", 0)
AutoItSetOption("TrayMenuMode", 1)
If UBound(ProcessList(@ScriptName)) > 2 Then
    Exit
EndIf

TraySetIcon("shell32.dll", 20)
HotKeySet("!{F1}", "password")
TraySetToolTip(@UserName & ": Inactivity Program")
TraySetState()

Global $USE_TOOLTIP = True
Global $start
Global $gmin, $lbl
Global $warninggui, $gui
Global $WinAct, $warningclose, $trans
Dim $start
Dim $dll
Dim $ADDTIME = ""
Dim $TIME_WAS_ADDED
Dim $TIMER
Dim $displayed = 0
Dim $displayed5 = 0
Dim $displayed2 = 0
Dim $displayed1 = 0
Dim $tipshowed

Dim $oldpos[2]
Dim $pos[2]  ;'for x,y
$pos = MouseGetPos()

Dim $s_keys[117] = [116, _
        "01", "02", "04", "05", "06", "08", "09", "0C", "0D", "10", _
        "11", "12", "13", "14", "1B", "20", "21", "22", "23", "24", _
        "25", "26", "27", "28", "29", "2A", "2B", "2C", "2D", "2E", _
        "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", _
        "41", "42", "44", "45", "46", "47", "48", "49", "4A", "4B", "4C", _
        "4D", "4E", "4F", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", _
        "5A", "5B", "5C", "60", "61", "62", "63", "64", "65", "66", _
        "67", "68", "69", "6A", "6B", "6C", "6D", "6E", "6F", "70", _
        "71", "72", "73", "74", "75", "76", "77", "78", "79", "7A", _
        "7B", "7C", "7D", "7E", "7F", "80H", "81H", "82H", "83H", "84H", _
        "85H", "86H", "87H", "90", "91", "A0", "A1", "A2", "A3", "A4", "A5"]
$dll = DllOpen("user32.dll")
$start = TimerInit()


While 1
    
    If FileExists(@ScriptDir & "\msg" & @ComputerName & ".txt") Then
        $sentmessage = FileRead(@ScriptDir & "\msg" & @ComputerName & ".txt")
        ConsoleWrite(@CRLF & "reading msg" & @CRLF)
        readmessage(@ComputerName, $sentmessage)
    EndIf
    
    
    
    If FileExists(@ScriptDir & "\end" & @ComputerName & ".txt") Then
        FileDelete(@ScriptDir & "\end" & @ComputerName & ".txt")
        _ShutDown(2)
    EndIf
    
    
    If FileExists(@ScriptDir & "\link1_" & @ComputerName & ".txt") Then
        Run("explorer.exe http://www.stdl.org/library_policies.asp#conduc")
        FileDelete(@ScriptDir & "\link1_" & @ComputerName & ".txt")
    EndIf
    
;inactivity checks
    For $y = 1 To $s_keys[0]
        If _IsPressed ($s_keys[$y], $dll) Then
            $start = TimerInit()
            ConsoleWrite(@CRLF & "Timer restarted with key " & $s_keys[$y] & " @ " & $start & @CRLF)
        EndIf
    Next
    
    $oldpos[0] = $pos[0]
    $oldpos[1] = $pos[1]
    $pos2 = MouseGetPos()
    
    $Mouse3 = $oldpos[0] + $oldpos[1]
    $Mouse4 = $pos2[0] + $pos2[1]
    If $Mouse3 <> $Mouse4 Then
        $start = TimerInit()
        ConsoleWrite(@CRLF & "Timer restarted with mouse @ " & $start & @CRLF)
    EndIf
    $pos3 = MouseGetPos()
    $pos[0] = $pos3[0]
    $pos[1] = $pos3[1]
    
    If TimerDiff($start) > 300000 Then
    ;'inactivity timer above [5 min inactivity], below we are WARNING
        
        $w = 250
        $h = 180
        $dw = (@DesktopWidth - $w) / 2
        $dh = (@DesktopHeight - $h) / 2
        $msg = "Inactivity Detected"
    ;' inactivity gui
        $warninggui = GUICreate(@UserName, $w, $h, $dw, $dh, BitOR($WS_POPUP, $WS_BORDER), $GUI_DISABLE)
    ;$WS_POPUPWINDOW instead of 0 to remove window and descrease height
        GUISetBkColor(0xFFFFE7); 'light yellow
        GUICtrlCreateLabel(@UserName, 25, 1, 120, 20)
        GUICtrlSetFont(-1, 11, 80, 0, "Times New Roman")
        GUICtrlSetColor(-1, 0xFD0F03)   ; 'Red
        GUICtrlCreateIcon("shell32.dll", 27, 5, 1, 15, 15)
        GUICtrlCreateLabel($msg, 0, 55, 250, -1, $SS_CENTER)
        GUICtrlSetColor(-1, 0x000000)   ; 'Black
        GUICtrlSetFont(-1, 13, 600, 0, "Helvetica")
        
        GUISetState(@SW_SHOW, $warninggui)
        
        
        $pos1 = MouseGetPos()
        $Mouse1 = $pos1[0] + $pos1[1]
        
        $Label_4 = GUICtrlCreateLabel("0%", 20, 80, 20, 20)
        GUICtrlSetFont(-1, 7, '', '', "Verdana")
        $Label_4_1 = GUICtrlCreateLabel("100%", 210, 80, -1, 20)
        GUICtrlSetFont(-1, 7, '', '', "Verdana")
        $Progressbar1 = GUICtrlCreateProgress(25, 100, 200, 7, $PBS_SMOOTH)
        $Label_6 = GUICtrlCreateLabel("Move mouse to stop count down" & @CRLF & "", 35, 120, 180, 60, $SS_CENTER)
        GUICtrlSetColor(-1, 0x000000)   ; 'Black
        GUICtrlSetFont(-1, 10, 400, 0, "Helvetica")
        $s = 0
        $ss = 0
        For $i = $s To 100 Step 2
            GUICtrlSetData($Progressbar1, $i)
;~
            $pos2 = MouseGetPos()
            $Mouse2 = $pos2[0] + $pos2[1]
            
            If $Mouse1 <> $Mouse2 Then
                GUIDelete($warninggui)
                ExitLoop
                $pos1 = MouseGetPos()
                $start = TimerInit()
            EndIf
            For $y = 1 To $s_keys[0]
                If _IsPressed ($s_keys[$y], $dll) Then
                    GUIDelete($warninggui)
                    ExitLoop
                    $start = TimerInit()
                EndIf
            Next
;~  key stroke will activate timer again
            
            If FileExists(@ScriptDir & "\end" & @ComputerName & ".txt") Then
                
                $endpos = MouseGetPos()
                GUIDelete($warninggui)
                FileDelete(@ScriptDir & "\end" & @ComputerName & ".txt")
                _ShutDown(2)
                ExitLoop
                
            EndIf
            
            Sleep(800)
        Next
        $start = TimerInit()
        If $i > 100 Then
            GUIDelete($warninggui)
            FileDelete(@ScriptDir & "\end" & @ComputerName & ".txt")
            _ShutDown(2)
            ExitLoop
            
        EndIf
    EndIf
    
    
    Sleep(800)
WEnd

Func readmessage($compnum, $sentmessage)
    
    
    $msg = $sentmessage
    
    
    $WinAct = GUICreate("Warning", 350, 80, @DesktopWidth - 360, @DesktopHeight - 105, BitOR($WS_EX_DLGMODALFRAME, $WS_POPUPWINDOW), $WS_EX_TOPMOST + $GUI_DISABLE)
    GUISetBkColor(0xFAFF9F, $WinAct)
    
    $Label1 = GUICtrlCreateEdit($msg, 10, 8, 330, 50, BitOR($ES_READONLY, $ES_WANTRETURN, $WS_VSCROLL, $ES_MULTILINE, $SS_LEFT))
    GUICtrlSetFont(-1, 10, 300, 0, "Verdana")
    GUICtrlSetColor(-1, 0x000080)
    GUICtrlSetBkColor(-1, 0xFAFF9F)

    
    $stringleng2 = StringLen($msg) + 10
    $stringleng = Round($stringleng2 * 65)
    $msgclosebutton = GUICtrlCreateLabel("Closes Automatically.", 0, 65, 335, 25, $SS_RIGHT)
    GUICtrlSetFont(-1, 7, 400, 0, "Arial")
    GUICtrlSetColor(-1, 0xCDCDCD)

    WinSetTrans( 'Warning', '', 0)
    _GuiRoundCorners($WinAct, 1, 1, 20, 20)

    GUISetState()
    
    $trans = 1
    Do
        Sleep(5)
        WinSetTrans( 'Warning', '', $trans)
        $trans = $trans + 4
    Until $trans >= 255
    
    Sleep($stringleng)
    _close()
    
    FileDelete(@ScriptDir & "\msg" & @ComputerName & ".txt")
EndFunc  ;==>readmessage

Func endscript()
    
EndFunc  ;==>endscript
Func _close()

    Do
        Sleep(5)
        WinSetTrans( 'Warning', '', $trans)
        $trans = $trans - 1
    Until $trans = 0

    GUIDelete($WinAct)

EndFunc  ;==>_close
Func _GuiRoundCorners($h_win, $i_x1, $i_y1, $i_x3, $i_y3)
    Dim $pos, $ret, $ret2
    $pos = WinGetPos($h_win)
    $ret = DllCall("gdi32.dll", "long", "CreateRoundRectRgn", "long", $i_x1, "long", $i_y1, "long", $pos[2], "long", $pos[3], "long", $i_x3, "long", $i_y3)
    If $ret[0] Then
        $ret2 = DllCall("user32.dll", "long", "SetWindowRgn", "hwnd", $h_win, "long", $ret[0], "int", 1)
        If $ret2[0] Then
            Return 1
        Else
            Return 0
        EndIf
    Else
        Return 0
    EndIf
EndFunc  ;==>_GuiRoundCorners

Func _ShutDown($sd_method, $sd_leaveopen = "Program Manager", $sd_leaveopen2 = "Program Manager", $sd_leaveopen3 = "Program Manager")
    
    $i = 1
    If $sd_method = 1 Then
        $sd_windows = WinList()
        While 1
            If $sd_windows[$i][0] <> "" And BitAND( WinGetState($sd_windows[$i][1]), 2) And $sd_windows[$i][0] <> "Program Manager" Then
                WinClose($sd_windows[$i][0])
            EndIf
            $i = $i + 1
            If $i = $sd_windows[0][0] Then
                Shutdown(0)
                ExitLoop
            EndIf
        WEnd
    EndIf
    
    $i = 1
    If $sd_method = 2 Then
        $sd_windows = WinList()
        While 1
            If $sd_windows[$i][0] <> "" And BitAND( WinGetState($sd_windows[$i][1]), 2) And $sd_windows[$i][0] <> "Program Manager" Then
                WinClose($sd_windows[$i][0])
            EndIf
            $i = $i + 1
            If $i = $sd_windows[0][0] Then
                Shutdown(1)
                ExitLoop
            EndIf
        WEnd
    EndIf
    
    $i = 1
    If $sd_method = 3 Then
        $sd_windows = WinList()
        While 1
            If $sd_windows[$i][0] <> "" And BitAND( WinGetState($sd_windows[$i][1]), 2) And $sd_windows[$i][0] <> "Program Manager" Then
                WinClose($sd_windows[$i][0])
            EndIf
            $i = $i + 1
            If $i = $sd_windows[0][0] Then
                ExitLoop
            EndIf
        WEnd
    EndIf
    
    $i = 1
    If $sd_method = 4 Then
        $sd_windows = WinList()
        While 1
            If $sd_windows[$i][0] <> "" And BitAND( WinGetState($sd_windows[$i][1]), 2) And $sd_windows[$i][0] <> "Program Manager" And $sd_windows[$i][0] <> $sd_leaveopen And $sd_windows[$i][0] <> $sd_leaveopen2 And $sd_windows[$i][0] <> $sd_leaveopen3 Then
                WinClose($sd_windows[$i][0])
            EndIf
            $i = $i + 1
            If $i = $sd_windows[0][0] Then
                ExitLoop
            EndIf
        WEnd
    EndIf
EndFunc  ;==>_ShutDown

Func password()
    Send("#d")
    $promptadmin = InputBox("Enter Admin password", "what is the password?", '', "*", 200, 100, -1, -1, 25)
    If @error = 0 Then
        $pass = "mypass";could be changed
        If $promptadmin = $pass Then
            Exit
        Else
        EndIf
    Else
    EndIf
EndFunc  ;==>password
Posted (edited)

i removed unneccessary code.

;================================================================
;======================= iNACTIVITy =============================
;================================================================
#NoTrayIcon
#include-once
#include <Constants.au3>
#include <GUIConstants.au3>
#include <Date.au3>
#include <Misc.au3>
Opt("GUIOnEventMode", 1)
Opt("WinTitleMatchMode", 4)
If UBound(ProcessList(@ScriptName)) > 2 Then
    Exit
EndIf
Global $start
Dim $oldpos[2]
Dim $pos[2]
Dim $s_keys[117] = [116, _
        "01", "02", "04", "05", "06", "08", "09", "0C", "0D", "10", _
        "11", "12", "13", "14", "1B", "20", "21", "22", "23", "24", _
        "25", "26", "27", "28", "29", "2A", "2B", "2C", "2D", "2E", _
        "30", "31", "32", "33", "34", "35", "36", "37", "38", "39", _
        "41", "42", "44", "45", "46", "47", "48", "49", "4A", "4B", "4C", _
        "4D", "4E", "4F", "50", "51", "52", "53", "54", "55", "56", "57", "58", "59", _
        "5A", "5B", "5C", "60", "61", "62", "63", "64", "65", "66", _
        "67", "68", "69", "6A", "6B", "6C", "6D", "6E", "6F", "70", _
        "71", "72", "73", "74", "75", "76", "77", "78", "79", "7A", _
        "7B", "7C", "7D", "7E", "7F", "80H", "81H", "82H", "83H", "84H", _
        "85H", "86H", "87H", "90", "91", "A0", "A1", "A2", "A3", "A4", "A5"]
$dll = DllOpen("user32.dll")
$start = TimerInit()
$pos = MouseGetPos()

While 1
    

;inactivity checks
    For $y = 1 To $s_keys[0]
        If _IsPressed ($s_keys[$y], $dll) Then
            $start = TimerInit()
            ConsoleWrite(@CRLF & "Timer restarted with key " & $s_keys[$y] & " @ " & _NowTime() & @CRLF)
        EndIf
    Next
    
    $oldpos[0] = $pos[0]
    $oldpos[1] = $pos[1]
    $pos2 = MouseGetPos()
    
    $Mouse3 = $oldpos[0] + $oldpos[1]
    $Mouse4 = $pos2[0] + $pos2[1]
    If $Mouse3 <> $Mouse4 Then
        $start = TimerInit()
        ConsoleWrite(@CRLF & "Timer restarted with mouse @ " & _NowTime() & @CRLF)
    EndIf
    $pos3 = MouseGetPos()
    $pos[0] = $pos3[0]
    $pos[1] = $pos3[1]
    
    If TimerDiff($start) > 900000 Then
;'inactivity timer above [15 min inactivity], below we are WARNING
    ConsoleWrite(@CRLF & "Inactive for 15 minutes" & @CRLF);could be changed to whatever, eg. msgbox, shutdown
;$start = TimerInit();uncomment if you need to restart timer
    EndIf
    
    
    Sleep(800)
WEnd
Edited by joseedwin

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...