Solved

Killing Explorer Windows

Posted on 2001-08-22
11
416 Views
Last Modified: 2008-02-01
I'm looking for some help with identifying and killing open Internet Explorer windows.
I want to write a customized pop-up killer/net nanny prog that will either stop banner ads opening up, or let me kill them off from a list if they do.

What I need to know is how do I identify any/all open explorer windows, and then how do I terminate them.
I guess I'll need to use API calls???

How complex is it to catch the new explorer window before it opens (or maybe as it is opening look at a list of addresses I don't want to open).

Any help would be appreciated.
0
Comment
Question by:gordonfm
  • 2
  • 2
  • 2
  • +4
11 Comments
 
LVL 50

Expert Comment

by:Ryan Chong
ID: 6413298
Hi gordon,

Here is a sample that useful:

'Close an application using the API.

Private Declare Function FindWindow Lib "user32" Alias _
"FindWindowA" (ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Declare Function PostMessage Lib "user32" Alias _
"PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, _
ByVal wParam As Long, lParam As Any) As Long
Private Const WM_CLOSE = &H10
Private Sub cmdClose_Click()
   Dim winHwnd As Long
   Dim RetVal As Long
   winHwnd = FindWindow(vbNullString, Text1.Text)
   Debug.Print winHwnd
   If winHwnd <> 0 Then
       RetVal = PostMessage(winHwnd, WM_CLOSE, 0&, 0&)
       If RetVal = 0 Then
           MsgBox "Error posting message."
       End If
   Else
       MsgBox Text1.Text + " is not open."
   End If
End Sub

'Hope will help.
0
 
LVL 50

Expert Comment

by:Ryan Chong
ID: 6413304
sorry, after reRead your question, the code posted may not help you.
0
 
LVL 14

Expert Comment

by:wsh2
ID: 6413391
<ping>.. Listening
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 28

Accepted Solution

by:
AzraSound earned 100 total points
ID: 6413592
Go to Project -> References and select Microsoft Internet Controls.


To loop through open IE Windows:


Private WithEvents shWin As SHDocVw.ShellWindows

Private Sub Form_Load()
   Set shWin = New SHDocVw.ShellWindows
End Sub

Private Sub LoopThroughIEWins()
   Dim IEObj As SHDocVw.InternetExplorer
 
   For Each IEObj In shWin
      Debug.Print IEObj.LocationURL
   Next
End Sub



Also, the shWin object, which we declared WithEvents, has an event called WindowRegistered, which fires everytime a new IE window is invoked by the system.
0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6413785
This is the only API I have found that will get rid of an IE Explorer window that was created by another process.  Pass in it's hwnd to close it.


Public Declare Function SendMessageByNum Lib "user32" Alias "SendMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Public Const WM_SYSCOMMAND = &H112
Public Const SC_CLOSE = &HF060&

Public Function KillIE(hWnd as long) as Long

   KillIE = SendMessageByNum(hWnd, WM_SYSCOMMAND, SC_CLOSE, 0&)
End Function

NOTE:

None of these API's will kill the window!
lRetVal = SendMessage(hWnd, WM_CLOSE, ByVal CLng(0), ByVal CLng(0))
lRetVal = CloseHandle(hWnd)
lRetVal = DestroyWindow(hWnd)
0
 
LVL 28

Expert Comment

by:AzraSound
ID: 6413965
To kill the IE windows using my method:

Private Sub KillAllIEWins()
  Dim IEObj As SHDocVw.InternetExplorer

  For Each IEObj In shWin
     IEObj.Quit
  Next
End Sub
0
 
LVL 8

Expert Comment

by:Dave_Greene
ID: 6414023
NOTE:

I have never attempted AZ's method!  Cheers
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6414651
Hearing...
0
 
LVL 28

Expert Comment

by:Ark
ID: 6415720
0
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6416008
I think that it doesn't works with me/2000 since "all windows" appears as using ie interface.
0
 

Author Comment

by:gordonfm
ID: 6424295
AzraSound, you're code worked fine with what I needed.
Thanks to the other submissions, all comments have been taken on board, so they weren't wasted.

I have already implemented an ad-hoc popup killer for my own use (not clean enough to distribute!).
I am using a timer to update a listbox that display the IEObj as in your submission.
I couldn't find that WindowRegistered thing happening, so I've taken a shortcut I guess.

Again, thank you all.  Look out for my next question as to how to catch Explorer Windows BEFORE they open!

0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

766 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