Results 1 to 9 of 9

Thread: Detecting whether or not Internet Explorer is open

  1. #1

    Thread Starter
    New Member
    Join Date
    Apr 2001
    Location
    Birmingham, UK
    Posts
    12

    Question

    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

  2. #2
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    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
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  3. #3

    Thread Starter
    New Member
    Join Date
    Apr 2001
    Location
    Birmingham, UK
    Posts
    12

    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

  4. #4
    Megatron
    Guest
    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

  5. #5
    Megatron
    Guest
    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

  6. #6

    Thread Starter
    New Member
    Join Date
    Apr 2001
    Location
    Birmingham, UK
    Posts
    12

    Angry 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 StringByVal lpWindowName As String) As Long
    Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hWndi As LongByVal wMsg As LongByVal wParam As LonglParam 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_CLOSE00
    PostMessage hWndi
    WM_DESTROY00
    PostMessage hWndi
    WM_QUIT00
    End 
    If 
    Is this correct?
    Man who walks through airport turnstiles sideways is going to Bangkok

  7. #7
    Fanatic Member crispin's Avatar
    Join Date
    Aug 2000
    Location
    2 clicks west of a Quirkafleeg...Cornwall, England
    Posts
    754
    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]

  8. #8

    Thread Starter
    New Member
    Join Date
    Apr 2001
    Location
    Birmingham, UK
    Posts
    12

    Talking 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

  9. #9
    Megatron
    Guest
    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
  •  



Click Here to Expand Forum to Full Width