Hey I posted this same question in the thread that specifically deals with the Internet, but no one has responded :-( So I figured I would post it in here because maybe more people look in the general thread then in the other threads.
Here is my question: Is there a way to detect how many Internet Explorers are open? My program will open Internet Explorer and in the course of it running the mouse may click on a link that will open up a new browser window or it may even open up something like Real Player or Outlook and I want to kill all of them except the originial Internet Explorer window. Is there a way to do this?
I figured I would use this code to close the new Internet Explorer window:
I know this won't close other applications and will only close Internet Explorer, but I figured I have to start somewhere, LoL. If you happen to know how to close the program that was opened up regardless of whether it is Internet Explorer then I will be glad to listen.Code:Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Private Declare Function OpenProcess Lib "kernel32" (ByVal dwDesiredAccess As Long, ByVal bInheritHandle As Long, ByVal dwProcessId As Long) As Long Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long Private Declare Function GetExitCodeProcess Lib "kernel32" (ByVal hProcess As Long, lpExitCode As Long) As Long Private Declare Function TerminateProcess Lib "kernel32" (ByVal hProcess As Long, ByVal uExitCode As Long) As Long Private Const PROCESS_ALL_ACCESS = &H1F0FFF Private Sub Command1_Click() Dim lHwnd As Long Dim lProcess As Long Dim lExitCode As Long 'Get the Window Handle lHwnd = FindWindow("IEFrame", vbNullString) 'Get the ProcessID Call GetWindowThreadProcessId(lHwnd, lProcess) 'Get the Process Handle lProcess = OpenProcess(PROCESS_ALL_ACCESS, 0, lProcess) 'Get the Exitcode Call GetExitCodeProcess(lProcess, lExitCode) 'Terminate the Process Call TerminateProcess(lProcess, lExitCode) End Sub
Thanks in advance and I hope no one gets mad for me posting this in two seperate threads.
Publius




Reply With Quote