Solved

Killing Explorer Windows

Posted on 2001-08-22
11
387 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 49

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 49

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
 
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

706 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

14 Experts available now in Live!

Get 1:1 Help Now