Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Killing Explorer Windows

Posted on 2001-08-22
11
Medium Priority
?
442 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 54

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 54

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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 28

Accepted Solution

by:
AzraSound earned 400 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…
Suggested Courses

783 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