|
-
Jun 3rd, 2000, 05:24 AM
#1
Thread Starter
New Member
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:
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
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.
Thanks in advance and I hope no one gets mad for me posting this in two seperate threads.
Publius
-
Jun 3rd, 2000, 05:54 AM
#2
You can do something like this. Add a Listbox (List1) and a Command button (Command1):
Code:
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function GetWindowTextLength Lib "user32" Alias "GetWindowTextLengthA" (ByVal hwnd As Long) As Long
Private Sub Command1_Click()
Dim lngIE As Long
Dim strBuffer As String
Dim lngLength As Long
Dim intCount As Integer
Do
lngIE = FindWindowEx(0, lngIE, "IEFrame", vbNullString)
lngLength = GetWindowTextLength(lngIE)
strBuffer = Space(lngLength)
Call GetWindowText(lngIE, strBuffer, Len(strBuffer))
If Len(Trim(strBuffer)) > 0 Then
List1.AddItem Trim(strBuffer)
intCount = intCount + 1
End If
Loop Until lngIE = 0
MsgBox intCount & " Internet Explorer instances found."
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|