kalelreturns Posted January 29, 2016 Share Posted January 29, 2016 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. Link to comment Share on other sites More sharing options...
water Posted January 29, 2016 Share Posted January 29, 2016 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 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
MuffinMan Posted January 29, 2016 Share Posted January 29, 2016 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 Link to comment Share on other sites More sharing options...
kalelreturns Posted January 29, 2016 Author Share Posted January 29, 2016 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. Link to comment Share on other sites More sharing options...
kalelreturns Posted January 29, 2016 Author Share Posted January 29, 2016 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. Link to comment Share on other sites More sharing options...
kylomas Posted January 29, 2016 Share Posted January 29, 2016 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 Link to comment Share on other sites More sharing options...
kalelreturns Posted January 29, 2016 Author Share Posted January 29, 2016 nice thanks kylomas I'll test this out. Link to comment Share on other sites More sharing options...
kalelreturns Posted January 30, 2016 Author Share Posted January 30, 2016 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. Link to comment Share on other sites More sharing options...
water Posted January 30, 2016 Share Posted January 30, 2016 (edited) Should be: Consolewrite('sites switched to ' & $currsites & @CRLF) Edited January 30, 2016 by water My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
kalelreturns Posted January 30, 2016 Author Share Posted January 30, 2016 that fixed it. thanks Link to comment Share on other sites More sharing options...
water Posted January 30, 2016 Share Posted January 30, 2016 (edited) That was an easy one Edited January 30, 2016 by water My UDFs and Tutorials: Spoiler UDFs:Active Directory (NEW 2022-02-19 - Version 1.6.1.0) - Download - General Help & Support - Example Scripts - WikiExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example ScriptsOutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - WikiOutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - DownloadOutlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - WikiPowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - WikiTask Scheduler (NEW 2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs:Excel - Example Scripts - WikiWord - Wiki Tutorials:ADO - WikiWebDriver - Wiki Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now