Solved

Controlling IE via process

Posted on 2004-08-22
2
207 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
Comment Utility
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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now