Home All Groups Group Topic Archive Search About

Problem automating page in IE 8

Author
26 Jul 2010 11:25 PM
Norm
Hi,

I am using the following code to open a page to sign in to MyMsn and it
does not work in the same way as other secure sites do. I don't know if
Microsoft does something different(big grin here), but the code, which
I believe I got from Karl Peterson, shows 22 objects on the document,
but does not print anything for the obj type, obj name or obj value.
Passing the document to a timer to run HTML links does not show the
sign in boxes at all either. Is there another way to see the items on
this page and pass the email address and password to them?

Code:


Private Sub Form_Load()
Dim obj

    Set Explorer = New InternetExplorer
    Explorer.Navigate2 "http://my.msn.com/"


End Sub


Private Sub Explorer_DocumentComplete(ByVal pDisp As Object, URL As
Variant)
Dim obj
Dim i As Long
i = 0

    If pDisp Is Explorer Then
         'Debug.Print vbCrLf; "TYPE", "NAME", "VALUE"
       For Each obj In Explorer.Document.All()
          Debug.Print obj.Type, obj.Name, obj.Value
            i = i + 1
       Next
       Debug.Print "i = " & i
      If Not Explorer.Document Is Nothing Then Set Doc =
Explorer.Document
      Timer1.Enabled = True
    End If

End Sub

Private Sub Timer1_Timer()
Dim oTag As HTMLLinkElement
Dim i As Long
    Me.Timer1.Enabled = False
    i = 0

    For Each oTag In Doc.links
        i = i + 1
        Debug.Print oTag.innerText
    Next

    Debug.Print "oTag i = " & i
    Unload Me
End Sub

Thanks Norm

Author
27 Jul 2010 12:32 AM
Mike S
On 7/26/2010 4:25 PM, Norm wrote:
Show quoteHide quote
> Hi,
>
> I am using the following code to open a page to sign in to MyMsn and it
> does not work in the same way as other secure sites do. I don't know if
> Microsoft does something different(big grin here), but the code, which I
> believe I got from Karl Peterson, shows 22 objects on the document, but
> does not print anything for the obj type, obj name or obj value. Passing
> the document to a timer to run HTML links does not show the sign in
> boxes at all either. Is there another way to see the items on this page
> and pass the email address and password to them?
>
> Code:
>
>
> Private Sub Form_Load()
> Dim obj
>
> Set Explorer = New InternetExplorer
> Explorer.Navigate2 "http://my.msn.com/"
>
>
> End Sub
>
>
> Private Sub Explorer_DocumentComplete(ByVal pDisp As Object, URL As
> Variant)
> Dim obj
> Dim i As Long
> i = 0
>
> If pDisp Is Explorer Then
> 'Debug.Print vbCrLf; "TYPE", "NAME", "VALUE"
> For Each obj In Explorer.Document.All()
> Debug.Print obj.Type, obj.Name, obj.Value
> i = i + 1
> Next
> Debug.Print "i = " & i
> If Not Explorer.Document Is Nothing Then Set Doc = Explorer.Document
> Timer1.Enabled = True
> End If
>
> End Sub
>
> Private Sub Timer1_Timer()
> Dim oTag As HTMLLinkElement
> Dim i As Long
> Me.Timer1.Enabled = False
> i = 0
>
> For Each oTag In Doc.links
> i = i + 1
> Debug.Print oTag.innerText
> Next
>
> Debug.Print "oTag i = " & i
> Unload Me
> End Sub
>
> Thanks Norm


How about this approach:
- the project contains these references
   Microsoft Internet Controls
   Microsoft HTML Object Library
- input element iteration code found here:

http://www.vbmonster.com/Uwe/Forum.aspx/basic/7680/Internet-Explorer-Automation-with-VB6-Click-Buttons-Enter-Passwords

Private Sub btnOpenNewIE_Click()
     Dim n As Long
     Dim oCol As IHTMLElementCollection
     Dim oElement As IHTMLElement
     Set IE = CreateObject("InternetExplorer.Application")
     IE.Visible = True
     IE.Navigate2 "http://my.msn.com/"
     Do While IE.ReadyState <> READYSTATE_COMPLETE
         Sleep 100
         DoEvents
     Loop
     Form1.Caption = "page load complete"
     DoEvents
     Set oCol = IE.Document.All.tags("INPUT")
     For Each oElement In oCol
        Debug.Print oElement.className & "  " & oElement.Name
     Next
End Sub
Author
27 Jul 2010 1:19 AM
Norm
Mike S formulated the question :
Show quoteHide quote
> On 7/26/2010 4:25 PM, Norm wrote:
>> Hi,
>>
>> I am using the following code to open a page to sign in to MyMsn and it
>> does not work in the same way as other secure sites do. I don't know if
>> Microsoft does something different(big grin here), but the code, which I
>> believe I got from Karl Peterson, shows 22 objects on the document, but
>> does not print anything for the obj type, obj name or obj value. Passing
>> the document to a timer to run HTML links does not show the sign in
>> boxes at all either. Is there another way to see the items on this page
>> and pass the email address and password to them?
>>
>> Code:
>>
>>
>> Private Sub Form_Load()
>> Dim obj
>>
>> Set Explorer = New InternetExplorer
>> Explorer.Navigate2 "http://my.msn.com/"
>>
>>
>> End Sub
>>
>>
>> Private Sub Explorer_DocumentComplete(ByVal pDisp As Object, URL As
>> Variant)
>> Dim obj
>> Dim i As Long
>> i = 0
>>
>> If pDisp Is Explorer Then
>> 'Debug.Print vbCrLf; "TYPE", "NAME", "VALUE"
>> For Each obj In Explorer.Document.All()
>> Debug.Print obj.Type, obj.Name, obj.Value
>> i = i + 1
>> Next
>> Debug.Print "i = " & i
>> If Not Explorer.Document Is Nothing Then Set Doc = Explorer.Document
>> Timer1.Enabled = True
>> End If
>>
>> End Sub
>>
>> Private Sub Timer1_Timer()
>> Dim oTag As HTMLLinkElement
>> Dim i As Long
>> Me.Timer1.Enabled = False
>> i = 0
>>
>> For Each oTag In Doc.links
>> i = i + 1
>> Debug.Print oTag.innerText
>> Next
>>
>> Debug.Print "oTag i = " & i
>> Unload Me
>> End Sub
>>
>> Thanks Norm
>
>
> How about this approach:
> - the project contains these references
>    Microsoft Internet Controls
>    Microsoft HTML Object Library
> - input element iteration code found here:
>
> http://www.vbmonster.com/Uwe/Forum.aspx/basic/7680/Internet-Explorer-Automation-with-VB6-Click-Buttons-Enter-Passwords
>
> Private Sub btnOpenNewIE_Click()
>      Dim n As Long
>      Dim oCol As IHTMLElementCollection
>      Dim oElement As IHTMLElement
>      Set IE = CreateObject("InternetExplorer.Application")
>      IE.Visible = True
>      IE.Navigate2 "http://my.msn.com/"
>      Do While IE.ReadyState <> READYSTATE_COMPLETE
>          Sleep 100
>          DoEvents
>      Loop
>      Form1.Caption = "page load complete"
>      DoEvents
>      Set oCol = IE.Document.All.tags("INPUT")
>      For Each oElement In oCol
>         Debug.Print oElement.className & "  " & oElement.Name
>      Next
> End Sub

Mike,

Thanks for the information. I tried that and it worked until I signed
in once and then it would only show the first button and the page had
my email address already included, even though I have all autocomplete
in IE unchecked. There seems to be something different on Microsofts
site.

I used to just save the cookies and it would automatically signin, but
that appears to only work for one day now and then you have to sign in
again. The security on this site seems to be greater than my bank. ;-)

I will keep playing with it, but will probably just use FireFox as that
still remembers my cookies. :-Z

Norm
Author
27 Jul 2010 1:47 AM
Norm
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
Author
27 Jul 2010 2:38 AM
Mike S
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
Author
27 Jul 2010 11:42 PM
Norm
Mike S brought next idea :
Show quoteHide quote
> 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
Author
28 Jul 2010 6:47 AM
Mike S
On 7/27/2010 4:42 PM, Norm wrote:
Show quoteHide quote
> 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
Author
28 Jul 2010 9:08 PM
Norm
Mike S used his keyboard to write :
Show quoteHide quote
> 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
Author
29 Jul 2010 7:49 AM
Mike S
<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
Author
29 Jul 2010 1:55 PM
Mayayana
| 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.
Author
29 Jul 2010 8:38 PM
Norm
Mayayana wrote :
Show quoteHide quote
>> 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.

Mike, thanks for the information I will play around with that. I had a
routine to find the available size of the screen and then set the left,
top, width and height of the window. It just seemed really funny that
MS did not have a way to maximize the window. While searching I found a
lot of questions from users trying to get IE to open maximized and what
they were having to go through for something as simple as that.

Mayayana, thanks also for the information. It seems that MS quite often
takes the hard way to do things, and not always the best. :D

I was thinking of trying to make a vb program to play some web games,
but since I am still at the beginner level I am not sure I will be able
to accomplish it, but will probably try. There are a lot of what they
call game cheats out there, but I think most of them are written in
Java, not sure if any are done in vb. But thanks again everyday I learn
something, although some days I think I go backwards. lol

Norm
Author
30 Jul 2010 4:57 AM
Mike S
On 7/29/2010 1:38 PM, Norm wrote:
Show quoteHide quote
> Mayayana wrote :
>>> 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.
>
> Mike, thanks for the information I will play around with that. I had a
> routine to find the available size of the screen and then set the left,
> top, width and height of the window. It just seemed really funny that MS
> did not have a way to maximize the window. While searching I found a lot
> of questions from users trying to get IE to open maximized and what they
> were having to go through for something as simple as that.
>
> Mayayana, thanks also for the information. It seems that MS quite often
> takes the hard way to do things, and not always the best. :D
>
> I was thinking of trying to make a vb program to play some web games,
> but since I am still at the beginner level I am not sure I will be able
> to accomplish it, but will probably try. There are a lot of what they
> call game cheats out there, but I think most of them are written in
> Java, not sure if any are done in vb. But thanks again everyday I learn
> something, although some days I think I go backwards. lol
>
> Norm

Norm, Apologies, I overlooked using the IE.hwnd - this works for me:

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 oCol As IHTMLElementCollection
     Dim oElement As IHTMLElement
     Set IE = CreateObject("InternetExplorer.Application")
     IE.Visible = True
     IE.Navigate2 "http://my.msn.com/"
     Do While IE.ReadyState <> READYSTATE_COMPLETE
         Sleep 100
         DoEvents
     Loop
     ShowWindow IE.hwnd, SW_MAXIMIZE
     Set oCol = IE.Document.All.tags("INPUT")
     For Each oElement In oCol
        Debug.Print oElement.Classname & "  " & oElement.Name & "  " &
oElement.innerHTML
     Next
End Sub

Mike
Author
30 Jul 2010 6:02 AM
Norm
Mike S formulated on Thursday :
Show quoteHide quote
> On 7/29/2010 1:38 PM, Norm wrote:
>> Mayayana wrote :
>>>> 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.
>>
>> Mike, thanks for the information I will play around with that. I had a
>> routine to find the available size of the screen and then set the left,
>> top, width and height of the window. It just seemed really funny that MS
>> did not have a way to maximize the window. While searching I found a lot
>> of questions from users trying to get IE to open maximized and what they
>> were having to go through for something as simple as that.
>>
>> Mayayana, thanks also for the information. It seems that MS quite often
>> takes the hard way to do things, and not always the best. :D
>>
>> I was thinking of trying to make a vb program to play some web games,
>> but since I am still at the beginner level I am not sure I will be able
>> to accomplish it, but will probably try. There are a lot of what they
>> call game cheats out there, but I think most of them are written in
>> Java, not sure if any are done in vb. But thanks again everyday I learn
>> something, although some days I think I go backwards. lol
>>
>> Norm
>
> Norm, Apologies, I overlooked using the IE.hwnd - this works for me:
>
> 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 oCol As IHTMLElementCollection
>      Dim oElement As IHTMLElement
>      Set IE = CreateObject("InternetExplorer.Application")
>      IE.Visible = True
>      IE.Navigate2 "http://my.msn.com/"
>      Do While IE.ReadyState <> READYSTATE_COMPLETE
>          Sleep 100
>          DoEvents
>      Loop
>      ShowWindow IE.hwnd, SW_MAXIMIZE
>      Set oCol = IE.Document.All.tags("INPUT")
>      For Each oElement In oCol
>         Debug.Print oElement.Classname & "  " & oElement.Name & "  " &
> oElement.innerHTML
>      Next
> End Sub
>
> Mike

Mike,

No problem, I had already figured that out as at one time I had used
the Ie.hwnd for SetForegroundWindow.

Sometimes the days are just too long. :D

Norm