6401integramandj Posted August 9, 2017 Share Posted August 9, 2017 I am trying to open a webpage, login, wait until the next page loads and then launch an exe. I can get the page to open and i can get the exe to run. The problem is I don't need the exe to run until after i log in to the website. So basically, i need to open the page in IE and log in... Then once the next page loads... Run the exe. This is what i have so far... #include <IE.au3> Local $Winauth = "\\Server\RunThis.exe" $oIE = _IECreate() _IENavigate($oIE, "https://WebSite.com/accounts/service-login#") $body = _IEBodyReadText($oIE) If StringInStr($body, "Get verification code from your Authentication app.") Then Run( $Winauth,"") EndIf The problem i'm having is that i think it checks it once on the first page and then stops. How would I have it continue to search for the string until it finds it? Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted August 10, 2017 Moderators Share Posted August 10, 2017 @6401integramandj what website are you trying to automate? Have you checked to ensure you are not violating the TOS of that site? "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
6401integramandj Posted August 10, 2017 Author Share Posted August 10, 2017 (edited) @JLogan3o13 It's not the site i'm trying to automate. We have multi factor authentication for this site. The token software is installed on an in house server. I'm not trying to automate login or token generation in any way, i simply want the software to be launched after the user logs in and is redirected to the page where they enter the token. The only automation will be to open the website, read the page until a particular string of words are displayed, and then launch some software from our server. Sorry for any confusion. Edited August 10, 2017 by 6401integramandj Link to comment Share on other sites More sharing options...
iAmNewbe Posted August 14, 2017 Share Posted August 14, 2017 If that is the entire code you have, there is no looping structure to grab the page again, it is only doing it once. It also will just keep retrieving "https://WebSite.com/accounts/service-login#." The only way that I know of to do this is to create your own custom browser application with AutoIt unless you can grab the current page from an existing IE instance which I am not sure how to do. Anything like what you are trying to do that I have seen work uses custom browser plugins that allow the plugin and the exe to talk to each other. Since you initiated the IE instance you should have the handle id which you can use to target that specific IE instance. Link to comment Share on other sites More sharing options...
Trong Posted August 14, 2017 Share Posted August 14, 2017 If WinExists() Then Run() Regards, Link to comment Share on other sites More sharing options...
water Posted August 14, 2017 Share Posted August 14, 2017 @VIP Did you read the OP properly? He is looking for a string in a Browser Window. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
water Posted August 14, 2017 Share Posted August 14, 2017 Something like this: While 1 $body = _IEBodyReadText($oIE) If StringInStr($body, "Get verification code from your Authentication app.") Then Run( $Winauth,"") ExitLoop EndIf Sleep(500) ; wait half a second WEnd 6401integramandj 1 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
iAmNewbe Posted August 15, 2017 Share Posted August 15, 2017 (edited) I am not sure that will work @water There are two pages the initial one opened with the instance then the user logins and another page loads. I am not sure how you grab the second page. What you have there may work but wouldn't it be better to check when the page reloads instead of forever looping grabbing the page, wouldn't that use up a lot of resources? OR get the IP banned for too many connections, spamming the server? Edited August 15, 2017 by iAmNewbe Link to comment Share on other sites More sharing options...
water Posted August 15, 2017 Share Posted August 15, 2017 My loop does not reload the page. It simply grabs the currently displayed page and searches for the text (2 times a second - but the sleep time can be adjusted). My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
6401integramandj Posted August 15, 2017 Author Share Posted August 15, 2017 On 8/14/2017 at 0:24 PM, water said: Something like this: While 1 $body = _IEBodyReadText($oIE) If StringInStr($body, "Get verification code from your Authentication app.") Then Run( $Winauth,"") ExitLoop EndIf Sleep(500) ; wait half a second WEnd This works perfect @water, thank you so much. Link to comment Share on other sites More sharing options...
water Posted August 15, 2017 Share Posted August 15, 2017 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
6401integramandj Posted August 17, 2017 Author Share Posted August 17, 2017 So here is my code that works great. I was not aware of one thing though. Once the user logs on the first time, the authentication is good for 8 hours. If they run this script and log in, it works beautifully, but if they log out and log back in within the 8 hours, the .exe does not run and therefore the loop continues until i manually end it. I need a way stop this loop from running forever if the .exe doesn't run. #include <IE.au3> Local $Winauth = "\\server\WinAuth.exe" $oIE = _IECreate() _IENavigate($oIE, "https://website/service-login#") While 1 $body = _IEBodyReadText($oIE) If StringInStr($body, "Get verification code from your Authentication app.") Then Run( $Winauth,"") ExitLoop EndIf Sleep(250) ; wait a quarter of a second WEnd Link to comment Share on other sites More sharing options...
water Posted August 17, 2017 Share Posted August 17, 2017 Add a counter so you can exit the Loop after a certain amount of time has expired (at the moment 4 loops = 1 second). Or use TimerInit/TimerDiff. My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
6401integramandj Posted August 18, 2017 Author Share Posted August 18, 2017 23 hours ago, water said: Add a counter so you can exit the Loop after a certain amount of time has expired (at the moment 4 loops = 1 second). Or use TimerInit/TimerDiff. #include <IE.au3> Local $Winauth = "\\server\WinAuth-3.5.1\WinAuth.exe" Local $hTimer = TimerInit() ; Begin the timer and store the handle in a variable. Local $fDiff = TimerDiff($hTimer) ; Find the difference in time from the previous call of TimerInit. The variable we stored the TimerInit handlem is passed as the "handle" to TimerDiff. $oIE = _IECreate() _IENavigate($oIE, "https://website/service-login#") While 1 $body = _IEBodyReadText($oIE) If StringInStr($body, "Get verification code from your Authentication app.") Then Run( $Winauth,"") ElseIf $fDiff > 10000 Then ExitLoop EndIf Sleep(250) ; wait a quarter of a second WEnd Ok, i suck. What am I doing wrong? I want to learn this so bad. Link to comment Share on other sites More sharing options...
water Posted August 18, 2017 Share Posted August 18, 2017 This ends the Loop after 10 seconds: #include <IE.au3> Local $Winauth = "\\server\WinAuth-3.5.1\WinAuth.exe" $oIE = _IECreate() _IENavigate($oIE, "https://website/service-login#") Local $hTimer = TimerInit() ; Begin the timer and store the handle in a variable. While 1 $body = _IEBodyReadText($oIE) If StringInStr($body, "Get verification code from your Authentication app.") Then Run( $Winauth,"") ExitLoop ElseIf TimerDiff($hTimer) > 10000 Then ExitLoop EndIf Sleep(250) ; wait a quarter of a second WEnd My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki Link to comment Share on other sites More sharing options...
alien4u Posted August 18, 2017 Share Posted August 18, 2017 So it goes like this: 1- The user executes the script. 2- The Script opens a visible Internet Explorer instance. 3- The Script waits for the Verification Code message on the IE instance. 4- The Script executes an external .exe file. 5- The user closes that external .exe file and log off from the website. 5a - The user could just close the .exe file and also close the IE instance(IE window). So basically you need to add extra checking to your software flow, meaning you need to store that .exe file hWD and you also need to get that IE instance hWD and check with some conditionals when any of them get close and then exit your script or add another check to know when the user log off and something else. There are various scenarios where you should consider different behaviors and evaluate all the possible combinations. Kind Regards Link to comment Share on other sites More sharing options...
6401integramandj Posted August 18, 2017 Author Share Posted August 18, 2017 1 hour ago, water said: This ends the Loop after 10 seconds: #include <IE.au3> Local $Winauth = "\\server\WinAuth-3.5.1\WinAuth.exe" $oIE = _IECreate() _IENavigate($oIE, "https://website/service-login#") Local $hTimer = TimerInit() ; Begin the timer and store the handle in a variable. While 1 $body = _IEBodyReadText($oIE) If StringInStr($body, "Get verification code from your Authentication app.") Then Run( $Winauth,"") ExitLoop ElseIf TimerDiff($hTimer) > 10000 Then ExitLoop EndIf Sleep(250) ; wait a quarter of a second WEnd Once again, thank you kindly @water. Link to comment Share on other sites More sharing options...
water Posted August 19, 2017 Share Posted August 19, 2017 My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - 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