Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Killing Explorer Windows

Posted on 2001-08-22
11
Medium Priority
?
441 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +4
11 Comments
 
LVL 53

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 53

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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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 utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…
Suggested Courses

722 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