AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to force using same Internet Explorer Window session?

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
memoday



Joined: 18 Feb 2008
Posts: 17

PostPosted: Tue Feb 26, 2008 12:00 am    Post subject: How to force using same Internet Explorer Window session? Reply with quote

Dear all,

I am trying to create a script that should search a password-protected internal terminology database? I managed to create a script that more or less achieves what I was hoping for, but I have a problem now.

Whenever I use the hot key to run the script, it opens a new IE window which is very confusing, because it asks me all the time to enter my user name and password to login to the database. What I want to do is to have one single internet explorer window session and whenever I use the script, it goes to the current IE Window.

Also, it should open just IE, not Firefox even it is the default browser on my machine, because the terminology database website does not work well with Firefox.

Is there a way to get this accomplished?

Thank you in advance for your help which I really need.
Back to top
View user's profile Send private message
wOxxOm



Joined: 09 Feb 2006
Posts: 326

PostPosted: Tue Feb 26, 2008 3:51 am    Post subject: Reply with quote

it depends on script
maybe you can activate the existing browser window
Back to top
View user's profile Send private message Send e-mail Visit poster's website
memoday



Joined: 18 Feb 2008
Posts: 17

PostPosted: Wed Feb 27, 2008 12:13 am    Post subject: Reply with quote

wOxxOm wrote:
it depends on script
maybe you can activate the existing browser window


Thanks for your reply.

I want to have my script use the same IE Window for search. How to force such behavior in AHK?
Back to top
View user's profile Send private message
engunneer



Joined: 30 Aug 2005
Posts: 8255
Location: Maywood, IL

PostPosted: Wed Feb 27, 2008 12:16 am    Post subject: Reply with quote

there is a setting in IE you can turn on called "Reuse windows for launching shortcuts"

Or i am misreading what you want.
_________________

(Common Answers)
Back to top
View user's profile Send private message Visit poster's website
paulwarr



Joined: 21 Sep 2006
Posts: 32

PostPosted: Wed Feb 27, 2008 4:38 pm    Post subject: Reply with quote

@ memoday

Your server probably is setting a session-specific cookie for authentication; in Internet Explorer, this means that the *particular instance* of the browser is the only one for which the authentication information is valid. If this is true, then when you start a new tab (in IE7) or a new window (in IE5.x-IE7), a new browser instance is created; since the session cookie is not present in that window, you get prompted for new credentials.

To identify a specific instance of a web browser (either a specific tab or a specific window), your script needs to find the IE session in which the session cookie is running. (Remember that in IE7, this is *not* the same as the larger IE window - rather, it's the tab embedded in the larger IE window.)

The following (untested) snippet makes use both of the COM.ahk standard library, and code from http://www.autohotkey.com/forum/topic24930 initially written by Sean, "wrapped" by Guest:

Code:

COM_CoInitialize()
SetTitleMatchMode, 1
SearchTitleString := "blah"  ; Replace blah (in quotes) with a known substring of
                             ; the window title that shows at the top of the IE
                             ; instance you wish to use.
SearchNavString := "blah"    ; Replace blah (in quotes) with the search URL on
                             ; your server.

pweb := GetWebBrowser(SearchTitleString)  ; Find the applicable IE instance

COM_Invoke(pweb, "Navigate", SearchNavString)  ; Navigate to the search page
Loop   ;  until the search web page is fully loaded
{
   if (COM_Invoke(pweb,  "ReadyState") = 4)
      break
}
COM_Release(pweb)
ExitApp

; Following code from: http://www.autohotkey.com/forum/topic24930
; initially written by Sean, wrapped by Guest
GetWebBrowser(WinTitle)
{
   ControlGet, hIESvr, hWnd, , Internet Explorer_Server1, %WinTitle%
   If Not   hIESvr
   {
      return
   }
   DllCall("SendMessageTimeout", "Uint", hIESvr, "Uint", DllCall("RegisterWindowMessage", "str", "WM_HTML_GETOBJECT"), "Uint", 0, "Uint", 0, "Uint", 2, "Uint", 1000, "UintP", lResult)
   DllCall("oleacc\ObjectFromLresult", "Uint", lResult, "Uint", COM_GUID4String(IID_IHTMLDocument2,"{332C4425-26CB-11D0-B483-00C04FD90119}"), "int", 0, "UintP", pdoc)
   IID_IWebBrowserApp := "{0002DF05-0000-0000-C000-000000000046}"
   pweb := COM_QueryService(pdoc,IID_IWebBrowserApp,IID_IWebBrowserApp)
   COM_Release(pdoc)
   Return   pweb
}



HTH
Back to top
View user's profile Send private message
cursed
Guest





PostPosted: Wed Mar 26, 2008 4:26 pm    Post subject: same issue, no results Reply with quote

@ paulwarr / or whoever could help

I am trying to do the same thing without the search. After login in with my user name and password, i need to be able to create a new window under same session. I am using IE7.

I dled COM.ahk, setworkdir, copy any paste your code, and replaced the "blah" with the window title of the page i want to display. When i run the script, it executes then close. No new window was made and nothing happens. I am new to COM.ahk and i dont really understand the functions and what they do and there are no tutorials on this so its hard for newbies to read.

So, basically, i wanna be able to press F1, open new window of any URL under same cookie session. or IE window session, b/c i have to login with a user name and password, when the new window opens i have to re-enter my username and password everytime. Thanks for you help.
Back to top
paulwarr



Joined: 21 Sep 2006
Posts: 32

PostPosted: Sat Mar 29, 2008 4:10 pm    Post subject: Reply with quote

cursed wrote:
I am trying to do the same thing without the search. After login in with my user name and password, i need to be able to create a new window under same session. I am using IE7....

So, basically, i wanna be able to press F1, open new window of any URL under same cookie session. or IE window session, b/c i have to login with a user name and password, when the new window opens i have to re-enter my username and password everytime.

I don't think that you can do this.

The whole point to having "session cookies" set by a server is to force all subsequent interactions with that session cookie to take place in the same browser "instance". What that means for you is that, attempting to open a new window will start a new instance of your browser - without the session cookie. And since the new window ("browser instance") doesn't have your instance-specific session cookie, the server asks you to authenticate again.

What you'll need to do is to manipulate the first session window (by using the IE_LoadURL command to navigate to another page, for example).
cursed wrote:
I dled COM.ahk, setworkdir, copy any paste your code, and replaced the "blah" with the window title of the page i want to display. When i run the script, it executes then close. No new window was made and nothing happens.

The code that I included was a "snippet" - not meant to be a fully-running example. If the window opened, navigated to the page you desired, and then closed, then the script succeeded - that was all it was written to do. From the above example (and note the inserted comment in red):
Code:

Loop   ;  until the search web page is fully loaded
{
   if (COM_Invoke(pweb,  "ReadyState") = 4)
      break
}
; Your code for manipulating this downloaded page, or navigating to another page, should go here.
COM_Release(pweb)

cursed wrote:
The I am new to COM.ahk and i dont really understand the functions and what they do and there are no tutorials on this so its hard for newbies to read.

Oh, do I share your pain! Shocked The challenges here are many, because you not only have to understand the basics of AHK, but you have to understand at least the basics of how to make use of Microsoft's WebBrowser and Internet Explorer controls. If you want to manipulate the web pages that you're seeing in the control, then you need much more than a basic understanding of the Document Object Model (DOM) and/or Microsoft's mshtml interfaces, connection methods, and element types. So... even trying to write a tutorial that's "easy" enough for newcomers would be very difficult, indeed.

I'm in the middle of a big coding project, which will take me until the end of June. If there's still interest on this subject in July (and if no one else has begun the effort), I'll start to draft a tutorial that collects and exhaustively documents snippets of COM/DOM/mshtml code, oriented specifically to AHK users. But while I will try to make it as understandable as I can, I can make no promises that this tutorial will be "accessible" (readily understandable) by AHK newcomers. Fair enough?
Back to top
View user's profile Send private message
cursed
Guest





PostPosted: Mon Mar 31, 2008 9:04 pm    Post subject: thank you! Reply with quote

@ paulwarr

Hey man, thank you for your response and for your time. Yeah, even a tutorial which pointed people in the right direction or even explained the "skeleton" of How COM or any other "Expansion" functions worked. Would set people in the right direction, and they can figure stuff out on there own.

Back to the open same session window. I found that it works only when you use ctrl-n, which opens a new browser under same cookie session. Pretty basic, but works. I would actually like to learn, .NET. If you or anyone has a link to a tutorials, that was be greatly appreciated. Thanks, ttyl.
Back to top
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group