Jump to content

Autorun an autoit program


ctl
 Share

Recommended Posts

Hey guys, I've created a program that opens my website every 10 minutes, the problem is that after I open the site, my program closes and I want it to remain open.I want to create a program that opens my first program (the one that opens my website) whenever it is closed, is that possible? Thank you very much.

Link to comment
Share on other sites

You want to make a program that stays running so it can start another that doesn't?

Doesn't make sense.

Just add loop that checks the time and conditionally runs your functions based on it.

Or use task schedualer

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

I have this code

$Minutes = 10
Local $60Count = 0, $begin = TimerInit()

While $Minutes > $60Count

  

    $dif = TimerDiff($begin)

    $dif2 = StringLeft($dif, StringInStr($dif, ".") -1)

    $Count = int($dif/1000)

    $60Count = Int($Count / 60)

  

    ToolTip("Timp total de asteptare = " & $Minutes & " minute"& @CRLF & "Au trecut = " & $60Count & " minute" & @CRLF & "S-au scurs  = " & $Count & " secunde"& @CRLF & "Mili-Seunde = " & $dif2, 20, 20, "ctl", 1)

  

    Sleep(20)

  

WEnd
SoundPlay(@WindowsDir & "\media\tada.wav", 1)
 


#include <IE.au3>
Global $oIE = _IECreate ("http://www.mysite.com")
$hWnd = _IEPropertyGet($oIE, "hwnd")

WinSetState($hWnd, "", @SW_MAXIMIZE)

How could i make a loop, so that the program runs, after the site was opened ? I dont know how could i make a loop that runs again the counter, could help me with these?

Link to comment
Share on other sites

There are many ways you can do this type of thing, here's 1

You run a loop until minutes is a unit of 10, then call a function to carry out your tasks.

Then you loop until minutes is a different unit.

And start again.

#include <IE.au3>

While 1
    Sleep(1000)
    If StringRight(String(@MIN), 1) == '0' Then
        _DoMyStuff()
        SoundPlay(@WindowsDir & "\media\tada.wav", 1)
        Do
            Sleep(1000)
        Until StringRight(String(@MIN), 1) <> '0'
    EndIf
WEnd

Func _DoMyStuff()
    MsgBox(0, 0, 'Doing stuff')
    ;Global $oIE = _IECreate("http://www.mysite.com")
    ;$hWnd = _IEPropertyGet($oIE, "hwnd")
    ;WinSetState($hWnd, "", @SW_MAXIMIZE)
EndFunc   ;==>_DoMyStuff

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

Ok, that was simple, but now when I run my program with your code, I get the same result, my site is opened, but the timer is still frozen.

$Minutes = 1
Local $60Count = 0, $begin = TimerInit()
While $Minutes > $60Count
 
    $dif = TimerDiff($begin)
    $dif2 = StringLeft($dif, StringInStr($dif, ".") -1)
    $Count = int($dif/1000)
    $60Count = Int($Count / 60)
 
    ToolTip("Timp total de asteptare = " & $Minutes & " minute"& @CRLF & "Au trecut = " & $60Count & " minute" & @CRLF & "S-au scurs  = " & $Count & " secunde"& @CRLF & "Mili-Seunde = " & $dif2, 20, 20, "ctl", 1)
 
    Sleep(20)
 
WEnd

#include <IE.au3>
While 1
    Sleep(1000)
    If StringRight(String(@MIN), 1) == '0' Then
        _DoMyStuff()
        SoundPlay(@WindowsDir & "\media\tada.wav", 1)
        Do
            Sleep(1000)
        Until StringRight(String(@MIN), 1) <> '0'
    EndIf
WEnd
Func _DoMyStuff()
    Global $oIE = _IECreate("http://www.mysite.com")
    $hWnd = _IEPropertyGet($oIE, "hwnd")
    WinSetState($hWnd, "", @SW_MAXIMIZE)
EndFunc   ;==>_DoMyStuff

Ok, now this is weird, now its not working anymore, when time is running out, nothing happends, my site is not opening anymore and the timer is frozen.

Edited by ctl
Link to comment
Share on other sites

I don't know how to resolve this, you are right, I have put the code which opens my site in that loop, i don't know how could i get the time running again after the site opens... :(

Link to comment
Share on other sites

I don't really understand your problem.

How about this then.

While 1
    Sleep(1000)
    If StringRight(String(@MIN), 1) == '0' Then ; every 10 minutes run your script
        ShellExecute('path\to\your\script.exe')
        SoundPlay(@WindowsDir & "\media\tada.wav", 1)
        Do
            Sleep(1000)
        Until StringRight(String(@MIN), 1) <> '0';wait until it is no longer on the ten minute mark, to avoid spwning more processes.
    EndIf
WEnd

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

This is what i was looking in the first place. :D This is perfect, If i want to change the duration of the verification, to 20-30-40 minutes, i have to change the 1 ?

Like this:

While 2
    Sleep(1000)
    If StringRight(String(@MIN), 2) == '0' Then ; every 10 minutes run your script
        ShellExecute('D:\folder\script.exe')
        SoundPlay(@WindowsDir & "\media\tada.wav", 2)
        Do
            Sleep(1000)
        Until StringRight(String(@MIN), 2) <> '0';wait until it is no longer on the ten minute mark, to avoid spwning more processes.
    EndIf
WEnd

Or i could somehow verify every 20 minutes if my script is still running ?

Edited by ctl
Link to comment
Share on other sites

$iDuration = 20 ; minutes
$iTimer = TimerInit()

While 50025
    Sleep(1000)
    If TimerDiff($iTimer) >= (1000 * 60) * $iDuration Then ; every $iDuration minutes run your script
        ShellExecute('D:\folder\script.exe')
        SoundPlay(@WindowsDir & "\media\tada.wav", 2)
        $iTimer = TimerInit(); reset timer
    EndIf
WEnd

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

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