Solved

Killing Explorer Windows

Posted on 2001-08-22
11
409 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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 27

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

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…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

815 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

8 Experts available now in Live!

Get 1:1 Help Now