Solved

kill a specific process (IE page) VB.NET 2003

Posted on 2011-02-21
4
1,007 Views
Last Modified: 2012-05-11
Hi Experts,

My app will open apps 'Outlook', 'Notepad', etc... from WINFORM button.

But I want to open IE page with specific URL, but I also want to kill that specific web-page.

System.Diagnostics.Process.Start("IExplore.exe", "http://sample.com/")

'iexplore' is the process, but, if I have more than one IE page open, I don't want to close others.

Thanks,
Roberto
0
Comment
Question by:RobertoFreemano
[X]
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
4 Comments
 
LVL 8

Expert Comment

by:Toxacon
ID: 34946218
Keep track of the Process IDs (PIDs) so you can shut down the right IE process.
0
 
LVL 16

Expert Comment

by:Kalpesh Chhatrala
ID: 34948561
Sample Code

1. Start notepad
System.Diagnostics.Process.Start("notepad")

2. Start winword
System.Diagnostics.Process.Start("WINWORD")

3. Start excel
System.Diagnostics.Process.Start("Excel")

4. Start ie and parameter
System.Diagnostics.Process.Start("IExplore.exe", "http://vbnetsample.blogspot.com/")

5. Kill It!!
' Kill all notepad process
Dim pProcess() As Process = System.Diagnostics.Process.GetProcessesByName("notepad")

For Each p As Process In pProcess
p.Kill()
Next
0
 
LVL 12

Accepted Solution

by:
Hairbrush earned 100 total points
ID: 34950697
Hi, I think the problem with the code sample given by kalpesh is that it will kill the whole of IE?

I have tried the following code sample, and it works.  You will need to add a reference to the COM object c:\windows\system32\shdocvw.dll for this code to work.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        ' Get all opened IE instances
        Dim shellWindows As SHDocVw.ShellWindows = New SHDocVw.ShellWindowsClass()
        Dim ie As SHDocVw.InternetExplorer
        For Each ie In shellWindows
            ' Get URL of IE instance
            Console.WriteLine(ie.LocationURL)

            ' Close specific IE tab / instance
            If ie.LocationURL = "http://sample.com/" Then
                ie.Quit()
            End If

        Next ie

    End Sub

Open in new window

0
 

Author Closing Comment

by:RobertoFreemano
ID: 34953038
Magic ;)
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

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

733 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