|
-
Apr 23rd, 2001, 01:49 PM
#1
Thread Starter
New Member
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
Man who walks through airport turnstiles sideways is going to Bangkok
-
Apr 23rd, 2001, 01:55 PM
#2
Frenzied Member
You can use the
Code:
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.
Code:
If FindWIndow("IEFrame",vbNullString) <> 0
'ie is open
End If
-
Apr 23rd, 2001, 01:59 PM
#3
Thread Starter
New Member
Wow
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!
Man who walks through airport turnstiles sideways is going to Bangkok
-
Apr 23rd, 2001, 02:25 PM
#4
To close IE.
Code:
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:
Code:
handle = FindWindow("IEFrame", vbNullString)
If handle <> 0 Then PostMessage handle, WM_QUIT, 0, 0
-
Apr 23rd, 2001, 02:28 PM
#5
You should also send the WM_CLOSE and WM_DESTROY messages to free up additional resources.
Code:
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
-
Apr 26th, 2001, 03:19 AM
#6
Thread Starter
New Member
Closing
This doesn't close IEFrame, this closes VB. Have I done something wrong?
At the top of the form, in Declarations:
PHP Code:
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:
PHP Code:
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?
Man who walks through airport turnstiles sideways is going to Bangkok
-
Apr 26th, 2001, 03:27 AM
#7
Fanatic Member
clipsie
Code:
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....
Crispin
VB6 ENT SP5
VB.NET
W2K ADV SVR SP3
WWW.BLOCKSOFT.CO.UK
[Microsoft Basic: 1976-2001, RIP]
-
Apr 30th, 2001, 03:53 AM
#8
Thread Starter
New Member
Thankyou!
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
Man who walks through airport turnstiles sideways is going to Bangkok
-
Apr 30th, 2001, 03:24 PM
#9
No prob
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
|