Sign in to follow this  
Followers 0
jbennett

AutoIT exe to check the time

11 posts in this topic

#1 ·  Posted (edited)

Hi,

I've come up with an idea and just wondering if it's possible.

I want to create an AutoIT .exe file that remains in the taskbar at all times and checks the time.

If the time is midnight then it will execute a batch file.

Does anyone know if this is possible and how much processing power it would take?

thanks :-)

p.s. there is a valid reason as to why i'm avoiding scheduled tasks

Edited by jbennett

Share this post


Link to post
Share on other sites



I can't find _Timer_SetTimer in the helpfile?

thanks

Share this post


Link to post
Share on other sites

when you have the help file open, click on the index tab and you will find it in the list.

#AutoIt3Wrapper_au3check_parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
#include <Timers.au3>
#include <GuiStatusBar.au3>
#include <ProgressConstants.au3>

Opt("MustDeclareVars", 1)

Global $iMemo, $hStatusBar, $progress, $percent = 0, $direction = 1

_Example_CallBack()

Func _Example_CallBack()
    Local $hGUI, $iTimerProgress, $btn_change, $iWait = 10, $btn_state
    Local $aParts[3] = [75, 330, -1]
    
    $hGUI = GUICreate("Timers Using CallBack Function(s)", 400, 320)
    $iMemo = GUICtrlCreateEdit("", 2, 32, 396, 226, BitOR($WS_HSCROLL, $WS_VSCROLL))
    GUICtrlSetFont($iMemo, 9, 400, 0, "Courier New")
    $btn_state = GUICtrlCreateButton("Start Progress Bar", 70, 270, 100, 25)
    $btn_change = GUICtrlCreateButton("Change", 215, 270, 90, 25)
    GUICtrlSetState($btn_change, $GUI_DISABLE)
    $hStatusBar = _GUICtrlStatusBar_Create($hGUI, $aParts)
    _GUICtrlStatusBar_SetText($hStatusBar, "Timers")
    _GUICtrlStatusBar_SetText($hStatusBar, @TAB & @TAB & StringFormat("%02d:%02d:%02d", @HOUR, @MIN, @SEC), 2)
    $progress = GUICtrlCreateProgress(0, 0, -1, -1, $PBS_SMOOTH)
    GUICtrlSetColor($progress, 0xff0000)
    _GUICtrlStatusBar_EmbedControl($hStatusBar, 1, GUICtrlGetHandle($progress))
    GUISetState()

    _Timer_SetTimer($hGUI, 1000, "_UpdateStatusBarClock"); create timer

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ExitLoop
            Case $btn_state
                If GUICtrlRead($btn_state) = "Start Progress Bar" Then
                    $iTimerProgress = _Timer_SetTimer($hGUI, $iWait, "_UpdateProgressBar"); create timer
                    If @error Or $iTimerProgress = 0 Then ContinueLoop
                    GUICtrlSetData($btn_state, "Stop Progress Bar")
                    GUICtrlSetState($btn_change, $GUI_ENABLE)
                Else
                    GUICtrlSetState($btn_change, $GUI_DISABLE)
                    _Timer_KillTimer($hGUI, $iTimerProgress)
                    GUICtrlSetData($btn_state, "Start Progress Bar")
                EndIf
                
            Case $btn_change
                If $iWait = 10 Then
                    $iWait = 250
                Else
                    $iWait = 10
                EndIf
                MemoWrite("Timer for _UpdateProgressBar set at: " & $iWait & " milliseconds")
                $iTimerProgress = _Timer_SetTimer($hGUI, $iWait, "", $iTimerProgress); reuse timer with different interval
        EndSwitch
    WEnd
    ConsoleWrite("Killed All Timers? " & _Timer_KillAllTimers($hGUI) & @LF)
    GUIDelete()
EndFunc  ;==>_Example_CallBack

; call back function
Func _UpdateStatusBarClock($hWnd, $Msg, $iIDTimer, $dwTime)
    #forceref $hWnd, $Msg, $iIDTimer, $dwTime
    _GUICtrlStatusBar_SetText($hStatusBar, @TAB & @TAB & StringFormat("%02d:%02d:%02d", @HOUR, @MIN, @SEC), 2)
EndFunc  ;==>_UpdateStatusBarClock

; call back function
Func _UpdateProgressBar($hWnd, $Msg, $iIDTimer, $dwTime)
    #forceref $hWnd, $Msg, $iIDTimer, $dwTime
    $percent += 5 * $direction
    GUICtrlSetData($progress, $percent)
    If $percent = 100 Or $percent = 0 Then $direction *= -1
    If $percent = 100 Then
        GUICtrlSetColor($progress, 0xff0000)
    ElseIf $percent = 0 Then
        GUICtrlSetColor($progress, 0x0000ff)
    EndIf
EndFunc  ;==>_UpdateProgressBar

; Write a line to the memo control
Func MemoWrite($sMessage)
    GUICtrlSetData($iMemo, $sMessage & @CRLF, 1)
EndFunc  ;==>MemoWrite

Share this post


Link to post
Share on other sites

Hmm, Doesn't seem to exist in my AutoIT help file. Only downloaded it from the site yesterday, hmm

The code you posted seems very long in length?. Is that the sort of code I need to produce to get a batch file to run at a certain time?. Ouch

Thanks

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

No, you can cut out what you need. I'm confused as in why you can't find in the help file the command. What version of AutoIt are you running?

jbenett may be opening the "AutoIt3.chm" file directly which does not contain the UDF info.

"AutoIt.chm" on the other hand does (which is the link in the Start menu and what opens through "F1" in SciTE.

Edited by ResNullius

Share this post


Link to post
Share on other sites

Hmm, Doesn't seem to exist in my AutoIT help file. Only downloaded it from the site yesterday, hmm

The code you posted seems very long in length?. Is that the sort of code I need to produce to get a batch file to run at a certain time?. Ouch

Thanks

http://dundats.mvps.org/AutoIt/AutoIt3_Web...er_SetTimer.htm

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

jbenett may be opening the "AutoIt3.chm" file directly which does not contain the UDF info.

"AutoIt.chm" on the other hand does (which is the link in the Start menu and what opens through "F1" in SciTE.

Don't forget AutoIt3Help.exe, it will also list UDF's :P

Share this post


Link to post
Share on other sites

Thanks for the link to the _Timer_SetTimer information.

I must say "ouch" this code is long and I have no idea what to cut out of it.

Just trying to figure out whats required to ensure that at a specified time the timer will know that it should run a batch file. Ummm?

Can anyone give me some ideas because it's really rattling my brains.

Thanks

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

This should work but I haven't really tested it thoroughly.

#include <Date.au3>

$time = "12:00AM"
$batch = "C:\batch.bat"

While 1
    If StringTrimRight($time,2) = StringStripWS(StringTrimRight(_NowTime(), 6),8) _
        AND StringRight($time, 2) = StringRight(_NowTime(), 2) Then Run($batch)
    Do
        ;nothing
    Until StringTrimRight($time,2) <> StringStripWS(StringTrimRight(_NowTime(), 6),8) ;so it only runs once in that minute
WEnd
Edited by SoulA

Share this post


Link to post
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
Sign in to follow this  
Followers 0