Solved

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

Posted on 2011-02-21
4
982 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
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

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

773 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