kalelreturns

Need help rewriting my script

11 posts in this topic

So I have 0 coding experience so I pretty much just copied and pasted parts of this script together that I've made. It works, but it doesn't work the best.

This is script:

#include <file.au3>
Dim $aSite
If Not _FileReadToArray("websites.txt",$aSite) Then
   MsgBox(4096,"Error", " Error reading file to Array    error:" & @error)
   Exit
EndIf
While 1=1
$x = Random(1, $aSite[0], 1)
ShellExecute("C:\Program Files\Mozilla Firefox\firefox.exe", $aSite[$x])
; Msgbox(0,'Random Site', $aSite[$x])
Sleep(Random(45000, 180000, 1))
Send("!{F4}")
Sleep(5000)
Wend

Basicly what its suppose to do is open a random url from the url list I have in websites.txt. Then it waits for 45000-180000 and closes firefox and then the script just loops after that. Like I said, it works but every once in awhile it will hang when it starts over and I get this error message:

Firefox is already running, but is not responding. To open a new window, you must first close the existing Firefox process, or restart your system.

the script still runs so the window gets closed and the script starts again.

I'm pretty sure this is an issue with my poorly coded script because I've messed with firefox settings for days and I still get that same error.

If someone could help me pinpoint the problem and also rewrite my script I would greatly appreciate it.

Share this post


Link to post
Share on other sites



Welcome to AutoIt and the forum!

Seems that Send either does not reach the Firefox window or Firefox displays a popup (like: Do you really want to leave this site?") and your script does not handle this.
Then FF is still running when you open the next instance.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

You might try using ProcessExists and ProcessClose to make sure FF is not running before your ShellExecute command

#include <file.au3>
Dim $aSite
If Not _FileReadToArray("websites.txt",$aSite) Then
   MsgBox(4096,"Error", " Error reading file to Array    error:" & @error)
   Exit
EndIf
While 1=1
$x = Random(1, $aSite[0], 1)
If ProcessExists("firefox.exe") Then ; Check if FireFox process is running.
   ProcessClose ( "firefox.exe" )
EndIf
ShellExecute("C:\Program Files\Mozilla Firefox\firefox.exe", $aSite[$x])
; Msgbox(0,'Random Site', $aSite[$x])
Sleep(Random(45000, 180000, 1))
Send("!{F4}")
Sleep(5000)
Wend

 

Share this post


Link to post
Share on other sites

Doh. I don't know why I didn't think of adding the processexsists. Thanks for the help. I'll test this out and post an update.

Share this post


Link to post
Share on other sites

Oh also 1 more thing, I run this script 24/7 but every 12hrs I need to switch to a different websites.txt file. So what I have done is made a copy of the script but used a different websites.txt file. So every 12hrs I stop the original and start the copy script. Is there anyway I can put this all in one script so I don't have to use 2 different scripts.

Share this post


Link to post
Share on other sites

kalelreturns,

I try this...

#include <file.au3>
#include <date.au3>

local $aSite, $sTime = _nowcalc(), $currsites = "websites1.txt"
If Not _FileReadToArray($currsites, $aSite) Then
    MsgBox(4096, "Error", " Error reading file to Array    error:" & @error)
    Exit
EndIf
While 1 = 1
    $x = Random(1, $aSite[0], 1)
    If ProcessExists("firefox.exe") Then ; Check if FireFox process is running.
        ProcessClose("firefox.exe")
        ; wait for process to close
        While ProcessExists("firefox.exe")
            Sleep(100)
        WEnd
    EndIf
    ShellExecute("C:\Program Files\Mozilla Firefox\firefox.exe", $aSite[$x])
    ; Msgbox(0,'Random Site', $aSite[$x])
    Sleep(Random(45000, 180000, 1))
    Send("!{F4}")
    Sleep(5000)

    ; switch site files every 12 hours
    if _DateDiff('h',$stime,_NowCalc()) > 11 then
        $currsites = ( $currsites = 'websites1.txt' ? 'websites2.txt' : 'websites1.txt' )
        $stime = _nowcalc()
        _FileReadToArray($currsites, $aSite)
        ConsoleWrite('Sites switched to ' $currsites & @CRLF)
    endif

WEnd

Note: I added code to make sure that FF process closes.   Not tested as I don't use FF

kylomas


Forum Rules         Procedure for posting code

"I like pigs.  Dogs look up to us.  Cats look down on us.  Pigs treat us as equals."

- Sir Winston Churchill

Share this post


Link to post
Share on other sites

nice thanks kylomas I'll test this out.

Share this post


Link to post
Share on other sites

tried this out but got the following error on startup:

 

Line 29 (file "C:\documents and settings\user x86\desktop\websites.au3):

Consolewrite('sites switched to 'currsites & @CRLF)

Consolewrite('sites switched to ^error

Error: Badly formated variable or marco.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Should be:

Consolewrite('sites switched to ' & $currsites & @CRLF)

 

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

that fixed it. thanks

 

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

That was an easy one :)

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

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