Click to See Complete Forum and Search --> : Detecting whether or not Internet Explorer is open
clipsie
Apr 23rd, 2001, 01:49 PM
Hi,
I am a network manager of a school, and I need a little bit o' code to detect whether or not Iexplore is open.
I run a little VB program on each machine which tells me who's logged on, since when, and saves a desktop image every 60 seconds, but I would like it to tell me whether or not the user is browsing, and also, is it possible that you could tell me a line of code to close the browser (upon request) too?
Thanks muchly,
clipsie
Vlatko
Apr 23rd, 2001, 01:55 PM
You can use the
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
· lpClassName
Points to a null-terminated string that specifies the class name or is an atom that identifies the class-name string. If this parameter is an atom, it must be a global atom created by a previous call to the GlobalAddAtom function. The atom, a 16-bit value, must be placed in the low-order word of lpClassName; the high-order word must be zero.
· lpWindowName
Points to a null-terminated string that specifies the window name (the window’s title). If this parameter is NULL, all window names match.
If FindWIndow("IEFrame",vbNullString) <> 0
'ie is open
End If
clipsie
Apr 23rd, 2001, 01:59 PM
Wow, that was fast. Now what about closing the browser? And say I wanted to find out if they had Microsoft Word open?
Thanks Vlatko!
Megatron
Apr 23rd, 2001, 02:25 PM
To close IE.
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Const WM_QUIT = &H12
Usage:
handle = FindWindow("IEFrame", vbNullString)
If handle <> 0 Then PostMessage handle, WM_QUIT, 0, 0
Megatron
Apr 23rd, 2001, 02:28 PM
You should also send the WM_CLOSE and WM_DESTROY messages to free up additional resources.
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Const WM_QUIT = &H12
Private Const WM_DESTROY = &H2
Private Const WM_CLOSE = &H10
Private Sub Command1_Click()
hApp = FindWindow("IEFrame", vbNullString)
If hApp <> 0 Then
PostMessage hwnd, WM_CLOSE, 0, 0
PostMessage hwnd, WM_DESTROY, 0, 0
PostMessage hwnd, WM_QUIT, 0, 0
End If
End Sub
clipsie
Apr 26th, 2001, 03:19 AM
This doesn't close IEFrame, this closes VB. Have I done something wrong?
At the top of the form, in Declarations:
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 hWndi As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_QUIT = &H12
Private Const WM_DESTROY = &H2
Private Const WM_CLOSE = &H10
In the form, in an event sub:
hApp = FindWindow("IEFrame", vbNullString)
If hApp <> 0 Then
PostMessage hWndi, WM_CLOSE, 0, 0
PostMessage hWndi, WM_DESTROY, 0, 0
PostMessage hWndi, WM_QUIT, 0, 0
End If
Is this correct?
crispin
Apr 26th, 2001, 03:27 AM
clipsie
hApp = FindWindow("IEFrame", vbNullString)
If hApp <> 0 Then
PostMessage hWndi, WM_CLOSE, 0, 0
PostMessage hWndi, WM_DESTROY, 0, 0
PostMessage hWndi, WM_QUIT, 0, 0
End If
you return the window handle to the hApp variable, but then post the messages to hWndi (im guessing that if the hWnd doesn't exist then the messages get posted to either all top level windows or the default queue - thats why it closes VB - care to confrim Megatron??), you need to post the messages to hApp handle also....
clipsie
Apr 30th, 2001, 03:53 AM
Hello,
Thanks Vlatko, Megatron, Crispin for helping me -- it's working now. I'd had some sort of code in before that posted messages, and had forgotten to remove it and so on ... but it's sorted now.
Thankyou very much! A very happy chappie.
clipsie :D
Megatron
Apr 30th, 2001, 03:24 PM
No prob :)
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.