Jump to content

IE automation : how to discard previous user sessions?


Recommended Posts

Hi all,

I'm very puzzled.

When I perform the action below manually :

- open IE

- go to the page https://directory.xxxxxxxx.com/

...then I see the sign-on page of my company, prompting me for my credentials (login+password) in a simple HTML form

When I execute the code below :

#include <IE.au3>

Func UserStatus($visible)
    $o_IE = _IECreate("https://directory.xxxxxxxxx.com/userstatus", 0, $visible)
    return 1
EndFunc 

if UserStatus(1) = 0 then ConsoleWrite("success"&@CRLF)

... Then there are 2 strange things happening :

1/ I *do* get logged in (without seeing the login page first), as if the applicaiton remembered a previous successful login. I have deleted the cookies, passwords, forms... from IE.

2/ I see the message "success" at the end of the execution.

There must be something awfully obvious (the code is so simple!) but I can't see it.

Thanks!

Link to comment
Share on other sites

Maybe you already have an IE window open

No, no, I've checked the processes. no iexplore.exe process running. And as I said it's ONLY the window open by Scite that's automatically logged in. I have closed and re-opened SciTe, it didn't help.

I also thought that it might come from the company's proxy keeping some kind of session but I can't figure out on what it would be based. Does an AutoIt script have some kind of unique identifier that would cause the proxy to recognize it at its next connection attempt? It doesn't sound very likely...

Link to comment
Share on other sites

Your login information is being stored in "session cookies". Session cookies live in the browser context and are destroyed when the browser exits. The confusing thing is that one iexplore process can host multiple browser instances and session cookies are shared accross all instances in the same iexplore process.

To get the behaviour you want, you must force a new iexplore process. Here is the method I typically use:

Global $oIE
If Not IsObj($oIE) Then
 $sRandom = "about:blank-" & Random(1000000, 9999999, 1)
 $sIE_pid = Run(@ProgramFilesDir & "\Internet Explorer\iexplore.exe " & $sRandom)
 Local $i_timer = TimerInit()
 While Not IsObj($oIE)
  If Int(TimerDiff($i_timer) / 1000) > 45 Then _
   ConsoleWrite("Failed to open browser" & @CRLF)
  $oIE = _IEAttach($sRandom, "url")
  Sleep(100)
 WEnd
EndIf

$oIE will be attached to this new browser and you can _IENavigate where you want to go.

Dale

Free Internet Tools: DebugBar, AutoIt IE Builder, HTTP UDF, MODIV2, IE Developer Toolbar, IEDocMon, Fiddler, HTML Validator, WGet, curl

MSDN docs: InternetExplorer Object, Document Object, Overviews and Tutorials, DHTML Objects, DHTML Events, WinHttpRequest, XmlHttpRequest, Cross-Frame Scripting, Office object model

Automate input type=file (Related)

Alternative to _IECreateEmbedded? better: _IECreatePseudoEmbedded  Better Better?

IE.au3 issues with Vista - Workarounds

SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y

Doesn't work needs to be ripped out of the troubleshooting lexicon. It means that what you tried did not produce the results you expected. It begs the questions 1) what did you try?, 2) what did you expect? and 3) what happened instead?

Reproducer: a small (the smallest?) piece of stand-alone code that demonstrates your trouble

Link to comment
Share on other sites

Your login information is being stored in "session cookies". Session cookies live in the browser context and are destroyed when the browser exits.

This makes me a bit suspicious with your solution. Indeed, I said several times that between 2 tests there are NO iexplore.exe processes running. I kill them all and restart from scratch.

Anyway, I'm more than willing to try your solution, that could solve many other forecoming issues.

I'm just not very sure of the lifecycle of the "$o_IE" object in that case. Check the code below :

Func ResetBrowser(ByRef $o_IE, $url)

    If Not IsObj($o_IE) Then
         $sRandom = "about:blank-" & Random(1000000, 9999999, 1)
         $sIE_pid = Run(@ProgramFilesDir & "\Internet Explorer\iexplore.exe " & $sRandom)
         Local $i_timer = TimerInit()
         While Not IsObj($o_IE)
              If Int(TimerDiff($i_timer) / 1000) > 45 Then _
                  ConsoleWrite("Failed to open browser" & @CRLF)
              $o_IE = _IEAttach($sRandom, $url)
              Sleep(100)
         WEnd
    EndIf

EndFunc

Local $o_IE
ResetBrowser ($o_IE, "https://directory.xxxxxxxxx.com")

I get the following result :

- An IE window is created

- It points to page "about:blank-yyyyyyyyyy" (where yyyyyyyyyy is a random number)

- the script is stuck in an infinite loop, displaying message "--> IE.au3 V2.4-0 Error from function _IEAttach, $_IEStatus_InvalidValue (Invalid Mode Specified)". I have to terminate it manually.

Am I properly using your method?

Maybe I don't understand well the difference between _IEcreate and _IEAttach.

Edit : I was misunderstanding the use of parameter "url".

I will post a new update once I have tested your method properly.

Edited by MonsieurOUXX
Link to comment
Share on other sites

This makes me a bit suspicious with your solution. Indeed, I said several times that between 2 tests there are NO iexplore.exe processes running. I kill them all and restart from scratch.

Despite my skepticism, your solution worked perfectly. I'm still not sure why, though. Thank you so much! I could never have figured that out myself...

Code source below.

#include <IE.au3>


Func _IECreateSafe($visible)
    Local $o_IE
    If Not IsObj($o_IE) Then
         $sRandom = "about:blank-" & Random(1000000, 9999999, 1)
         $sIE_pid = Run(@ProgramFilesDir & "\Internet Explorer\iexplore.exe " & $sRandom, "", $visible)
         Local $i_timer = TimerInit()
         While Not IsObj($o_IE)
              If Int(TimerDiff($i_timer) / 1000) > 45 Then _
                  ConsoleWrite("Failed to open browser" & @CRLF)
              $o_IE = _IEAttach($sRandom, "url")
              Sleep(100)
          WEnd
    EndIf
    
    return $o_IE
EndFunc


Local $o_IE = _IECreateSafe($visible)
_IENavigate($o_IE, "http:/www.google.com")
_IEQuit($o_IE)
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...