From: Norm on
Mike S brought next idea :
> On 7/26/2010 6:47 PM, Norm wrote:
>> Not sure what I was doing wrong, but it is working now. :D
>>
>> If I delete all cookies from the cookie folder and the Temporary
>> Internet Folder it will open correctly to the sign in page. If I leave
>> the cookies it will open to My Msn page. At least for today. ^^
>>
>> I will see what it does tomorrow.
>>
>> Thanks again,
>> Norm
>
> Norm,
>
> How about setting up IE delete cookies and temporary files when it is closed?
>
> http://www.mvps.org/winhelp2002/delcache.htm
>
> Mike

Mike,

I already do that, but when opened again IE8 will go to the MSN page,
but not sign into mine. I think it has something to do with the Live
login that is now required. The only way I can get it to work is by
running a program I wrote to clean all temporary internet files and
cookies before running the automated opening of the browser. If I
manually clean all files first it will open correctly.

Norm


From: Mike S on
On 7/27/2010 4:42 PM, Norm wrote:
> Mike S brought next idea :
>> On 7/26/2010 6:47 PM, Norm wrote:
>>> Not sure what I was doing wrong, but it is working now. :D
>>>
>>> If I delete all cookies from the cookie folder and the Temporary
>>> Internet Folder it will open correctly to the sign in page. If I leave
>>> the cookies it will open to My Msn page. At least for today. ^^
>>>
>>> I will see what it does tomorrow.
>>>
>>> Thanks again,
>>> Norm
>>
>> Norm,
>>
>> How about setting up IE delete cookies and temporary files when it is
>> closed?
>>
>> http://www.mvps.org/winhelp2002/delcache.htm
>>
>> Mike
>
> Mike,
>
> I already do that, but when opened again IE8 will go to the MSN page,
> but not sign into mine. I think it has something to do with the Live
> login that is now required. The only way I can get it to work is by
> running a program I wrote to clean all temporary internet files and
> cookies before running the automated opening of the browser. If I
> manually clean all files first it will open correctly.
>
> Norm

It sounds like there are only two or three states that you will see when
the page loads in your browser, is that true? How about testing for the
values of the input fields so you can detect which state it's in, then
perform the appropriate action in code? I think this should become
pretty clear if you will keep loading the page over and over and then
see what input fields exist and what their values are. Once you identify
all of the various combinations of what input fields exist and what
their values are, you can write conditionals to handle each condition.
Does that approach sound like it will work for you?

Mike

From: Norm on
Mike S used his keyboard to write :
> On 7/27/2010 4:42 PM, Norm wrote:
>> Mike S brought next idea :
>>> On 7/26/2010 6:47 PM, Norm wrote:
>>>> Not sure what I was doing wrong, but it is working now. :D
>>>>
>>>> If I delete all cookies from the cookie folder and the Temporary
>>>> Internet Folder it will open correctly to the sign in page. If I leave
>>>> the cookies it will open to My Msn page. At least for today. ^^
>>>>
>>>> I will see what it does tomorrow.
>>>>
>>>> Thanks again,
>>>> Norm
>>>
>>> Norm,
>>>
>>> How about setting up IE delete cookies and temporary files when it is
>>> closed?
>>>
>>> http://www.mvps.org/winhelp2002/delcache.htm
>>>
>>> Mike
>>
>> Mike,
>>
>> I already do that, but when opened again IE8 will go to the MSN page,
>> but not sign into mine. I think it has something to do with the Live
>> login that is now required. The only way I can get it to work is by
>> running a program I wrote to clean all temporary internet files and
>> cookies before running the automated opening of the browser. If I
>> manually clean all files first it will open correctly.
>>
>> Norm
>
> It sounds like there are only two or three states that you will see when the
> page loads in your browser, is that true? How about testing for the values of
> the input fields so you can detect which state it's in, then perform the
> appropriate action in code? I think this should become pretty clear if you
> will keep loading the page over and over and then see what input fields exist
> and what their values are. Once you identify all of the various combinations
> of what input fields exist and what their values are, you can write
> conditionals to handle each condition. Does that approach sound like it will
> work for you?
>
> Mike

Mike,

Since I am only doing this for myself, I went the easy way. When the
little program starts it cleans both the temporary and cookie file.
This only adds about 1 sec to the browser opening and signing in. If
this was for public consuption I would probably look for a better
solution. lol

Like I said earlier I could just use firefox or chrome as they don't
have this problem. I can save the cookies used for signing in with them
and they work just fine. I have always had a problem with cleaning IE's
temp files and cookies and saving the ones I wanted. I think it is
because they seem to tie the two files together. Anyway thanks for all
the input and help. This problem is kind of like all the trouble
everyone seems to have with just getting IE to open maximized. I was
surprised to find that using automation with IE that there was no
maximized setting. :o)

Thanks again,
Norm


From: Mike S on
<snip>
> I was surprised to find that using automation with IE that there was no
> maximized setting. :o)
<snip>

That's not too hard to manage, this is just thrown together quickly
using the page below. There's probably a shorter way to find the window
if the title text is always exactly the same, but if there may be minor
variations in the title text this might give you a little leeway by
allowing you to enter generic title text text and still allow you to
find the window.

How To Get a Window Handle Without Specifying an Exact Title
http://support.microsoft.com/kb/147659

Form Code:

Option Explicit

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long,
ByVal nCmdShow As Long) As Long

Private Const SW_MAXIMIZE = 3

Public IE As Object

Private Sub btnOpenNewIE_Click()
Dim WinHandle As Long
Dim oCol As IHTMLElementCollection
Dim oElement As IHTMLElement
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True
DoEvents
IE.Navigate2 "http://my.msn.com/"
Do While IE.ReadyState <> READYSTATE_COMPLETE
Sleep 100
DoEvents
Loop
MaximizeIEWindow
Set oCol = IE.Document.All.tags("INPUT")
For Each oElement In oCol
Debug.Print oElement.Classname & " " & oElement.Name & " " &
oElement.innerHTML
Next
End Sub

Public Sub MaximizeIEWindow()
Static hWnds() As Long, r As Long
'enter the title of your IE window in the quotation marks
r = FindWindowLike(hWnds(), 0, "Welcome to Windows Live - Windows
Internet Explorer", "*", Null)
If r > 0 Then ShowWindow hWnds(r), SW_MAXIMIZE
End Sub

Private Sub btnEnd_Click()
IE.Quit
DoEvents
Set IE = Nothing
Unload Form1
Set Form1 = Nothing
End Sub

Module Code:

Option Explicit

Declare Function SetFocusAPI Lib "user32" Alias "SetForegroundWindow"
(ByVal hwnd As Long) As Long
Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal
wCmd As Long) As Long
Declare Function GetDesktopWindow Lib "user32" () As Long
Declare Function GetWindowLW Lib "user32" Alias "GetWindowLongA"
(ByVal hwnd As Long, ByVal nIndex As Long) As Long
Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Declare Function GetClassName Lib "user32" Alias "GetClassNameA"
(ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount As
Long) As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA"
(ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long

Public Const GWL_ID = (-12)
Public Const GW_HWNDNEXT = 2
Public Const GW_CHILD = 5

Function FindWindowLike(hWndArray() As Long, ByVal hWndStart As
Long, WindowText As String, Classname As String, ID) As Long
Dim hwnd As Long
Dim r As Long
Static level As Long
Static iFound As Long
Dim sWindowText As String
Dim sClassname As String
Dim sID
' Initialize if necessary:
If level = 0 Then
iFound = 0
ReDim hWndArray(0 To 0)
If hWndStart = 0 Then hWndStart = GetDesktopWindow()
End If
' Increase recursion counter:
level = level + 1
' Get first child window:
hwnd = GetWindow(hWndStart, GW_CHILD)
Do Until hwnd = 0
DoEvents ' Not necessary
' Search children by recursion:
r = FindWindowLike(hWndArray(), hwnd, WindowText, Classname, ID)
' Get the window text and class name:
sWindowText = Space(255)
r = GetWindowText(hwnd, sWindowText, 255)
sWindowText = Left(sWindowText, r)
sClassname = Space(255)
r = GetClassName(hwnd, sClassname, 255)
sClassname = Left(sClassname, r)
' If window is a child get the ID:
If GetParent(hwnd) <> 0 Then
r = GetWindowLW(hwnd, GWL_ID)
sID = CLng("&H" & Hex(r))
Else
sID = Null
End If
' Check that window matches the search parameters:
If sWindowText Like WindowText And sClassname Like Classname Then
If IsNull(ID) Then
' If find a match, increment counter and
' add handle to array:
iFound = iFound + 1
ReDim Preserve hWndArray(0 To iFound)
hWndArray(iFound) = hwnd
ElseIf Not IsNull(sID) Then
If CLng(sID) = CLng(ID) Then
' If find a match increment counter and
' add handle to array:
iFound = iFound + 1
ReDim Preserve hWndArray(0 To iFound)
hWndArray(iFound) = hwnd
End If
End If
Debug.Print "Window Found: "
Debug.Print " Window Text : " & sWindowText
Debug.Print " Window Class : " & sClassname
Debug.Print " Window Handle: " & CStr(hwnd)
End If
' Get next child window:
hwnd = GetWindow(hwnd, GW_HWNDNEXT)
Loop
' Decrement recursion counter:
level = level - 1
' Return the number of windows found:
FindWindowLike = iFound
End Function

From: Mayayana on
| This problem is kind of like all the trouble
| everyone seems to have with just getting IE to open maximized. I was
| surprised to find that using automation with IE that there was no
| maximized setting. :o)
|

Almost everything is in there, but it's not all
ideally designed. There's TheaterMode (but don't
try to use that in combination with height/width
values in IE7/8). There are left/top/width/height
values. The Window object has 2 or 3 methods.
Etc.

The following simple VBScript demonstrates one
method:

Dim IE
Set IE = CreateObject("InternetExplorer.Application")
IE.Navigate "about:blank"
Do While IE.ReadyState <> 4
Loop
IE.Visible = True
IE.left = 0
IE.top = 0
IE.width = IE.document.parentwindow.screen.availwidth
IE.height = IE.document.parentwindow.screen.availheight


But there are problems with doing IE automation that's
not targetted to a specific situation. There are 3 distinct
issues aside from the issue of the DOM complexity:

1) Different versions of IE are different.

2) Starting with IE6 MS started trying to plan for security.
For instance, one used to be able to open a window in
theatermode (no chrome), set the size, dynamically write
the document content, and thereby create a msgbox that
looks just like a system msgbox. One also used to be able
to open an IE instance offscreen for various purposes. Those
functions were disabled for security reasons. ...It makes sense,
but MS makes different changes with each IE version, and
much of what makes IE automation so flexible involves hacks,
so the changes often break old code.
The security changes also involve all sorts of weirdo moves
like blocking downloads of certain file types even when downloads
are enabled... or showing the "information bar" to require specifically
allowing one thing or another... or preventing people from adjusting
local security settings...etc. As usual, Microsoft approached
the problem with excessive complexity and poor planning. So now
IE 7/8 users are free to get attacked by a driveby download --
and good luck to anyone who wants to adjust the script settings
that make that possible -- but only the tech-savvy can manage
to download an unsigned EXE.
The cookie issues you're running into may be connected with
security settings that vary by IE version.

3) Starting with IE6 MS decided to start conforming to basic
W3C agreement about Document structure. Again, they're
not consistent from one IE version to another. And now the IE
DOM in force depends on the content of the webpage loaded!
If the webpage contains one of several specific DOCTYPE tags
it will be treated as W3C conforming and the traditional IE
DOM will be broken. If the necessary DOCTYPE is not present
the page will be treated with "quirks mode", using the IE5
DOM, and the W3C methods will be broken. (I think there's also
a new META option to tell IE which IE version to emulate.)

So to make a long story short, you can do almost anything
you can think of with IE, but the version, security settings,
and DOCTYPE can all affect exactly how it's done.