Solved

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

Posted on 2011-02-21
4
939 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
4 Comments
 
LVL 8

Expert Comment

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

Expert Comment

by:Kalpesh Chhatrala
Comment Utility
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
Comment Utility
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
Comment Utility
Magic ;)
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
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.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

763 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

7 Experts available now in Live!

Get 1:1 Help Now