Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Controlling IE via process

Posted on 2004-08-22
2
210 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This article will show, step by step, how to integrate R code into a R Sweave document
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

809 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