Jump to content

Open an exe after opening a webpage


Recommended Posts

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

1.png

 

Then once the next page loads...

2.png

 

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

  • Moderators

@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

@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 by 6401integramandj
Link to comment
Share on other sites

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

@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 2022-02-19 - Version 1.6.1.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 (NEW 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

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

 

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

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 by iAmNewbe
Link to comment
Share on other sites

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 2022-02-19 - Version 1.6.1.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 (NEW 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

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

:)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

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

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 2022-02-19 - Version 1.6.1.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 (NEW 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

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

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 2022-02-19 - Version 1.6.1.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 (NEW 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

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

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

:)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2022-02-19 - Version 1.6.1.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 (NEW 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

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