Solved

Controlling IE via process

Posted on 2004-08-22
2
211 Views
Last Modified: 2010-04-17
Hi all,

Thank you all for all the help you've been so far !

I now know how to start IE via a process in VB.NET.  I also can make it start up with a certain web page and then do my processing of that page with window handles, etc.

But what I still need to know is once that process is up and running (IE) and I have the process object/ID, how can I give IE another URL and tell it go to that page as if the user interactively typed in a new URL and hit GO.  If that can be done, how do you also detect the page is completely done loading/rendering ?

For each page I need to display and process, I do NOT want to do the following:  start a process with IE with the web page displayed, do my processing, and kill the process...and repeat that for every page.  Since a process is already started with IE, I'd rather just use it for the next page.  

Any ideas ?

Thanks,

John

0
Comment
Question by:trzesniakj
2 Comments
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 11864616
Don't use a process to launch a new IE window.  Instead use IE Com object.  Go to Project --> Add Reference and switch to the COM tab.  Double click on "Microsoft Internet Controls" and hit Ok.

Try out the following code:
Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents Button1 As System.Windows.Forms.Button
    Friend WithEvents TextBox1 As System.Windows.Forms.TextBox
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.Button1 = New System.Windows.Forms.Button
        Me.TextBox1 = New System.Windows.Forms.TextBox
        Me.SuspendLayout()
        '
        'Button1
        '
        Me.Button1.Location = New System.Drawing.Point(224, 8)
        Me.Button1.Name = "Button1"
        Me.Button1.Size = New System.Drawing.Size(64, 24)
        Me.Button1.TabIndex = 0
        Me.Button1.Text = "Button1"
        '
        'TextBox1
        '
        Me.TextBox1.Location = New System.Drawing.Point(8, 8)
        Me.TextBox1.Name = "TextBox1"
        Me.TextBox1.Size = New System.Drawing.Size(208, 20)
        Me.TextBox1.TabIndex = 1
        Me.TextBox1.Text = "www.google.com"
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(292, 46)
        Me.Controls.Add(Me.TextBox1)
        Me.Controls.Add(Me.Button1)
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private WithEvents IE As SHDocVw.InternetExplorer

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If TextBox1.Text <> "" Then
            If IE Is Nothing Then
                IE = New SHDocVw.InternetExplorer
            End If

            IE.Visible = True
            IE.Navigate(TextBox1.Text)

            ' if you need the code to stay in the same sub and then
            ' continue, use this type of structure.
            ' otherwise use the documentcomplete event as below
            Do While IE.Busy
                Application.DoEvents()
            Loop

            ' page finished loading...
            ' do something in here
        End If
    End Sub

    Private Sub IE_DocumentComplete(ByVal pDisp As Object, ByRef URL As Object) Handles IE.DocumentComplete
        ' page finished loading...
        ' do something in here
    End Sub

End Class
0
 
LVL 3

Expert Comment

by:Santino_k
ID: 11867670
Use IE Com Object. I have done that in VC++. Refer to following URL for VB -
http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/webbrowser/browser_control_node_entry.asp

http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/webbrowser/browser_control_node_entry.asp


The above URL contents will give you detailed description/help/tutorial/reference of all IE programming.

Hope this helps.
Have a nice day!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
egit plugin on eclipse 8 95
ejb example issues 3 47
T-SQL: Preventing Duplicate Records from Being Returned When "Joining" Code Blocks 2 61
backup program with robocopy 6 69
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …

679 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question