6401integramandj

Open an exe after opening a webpage

18 posts in this topic

#1 ·  Posted

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? 

Share this post


Link to post
Share on other sites



#2 ·  Posted

@6401integramandj what website are you trying to automate? Have you checked to ensure you are not violating the TOS of that site?


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#3 ·  Posted (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 by 6401integramandj

Share this post


Link to post
Share on other sites

#4 ·  Posted

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. 

Share this post


Link to post
Share on other sites

#6 ·  Posted

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

#7 ·  Posted

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

 

1 person likes this

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

#8 ·  Posted (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 by iAmNewbe

Share this post


Link to post
Share on other sites

#9 ·  Posted

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

#10 ·  Posted

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.

Share this post


Link to post
Share on other sites

#11 ·  Posted

:)


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

#12 ·  Posted

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

Share this post


Link to post
Share on other sites

#13 ·  Posted

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

#14 ·  Posted

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.

Share this post


Link to post
Share on other sites

#15 ·  Posted

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

#16 ·  Posted

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
 

Share this post


Link to post
Share on other sites

#17 ·  Posted

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

Share this post


Link to post
Share on other sites

#18 ·  Posted

:)


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