• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 766
  • Last Modified:

vbscript - How To Prevent Users From Closing an IE window?


I am using internet explorer to show the results of my network logon script but I want to prevent the users from close it. Any idea on how to do that?

Here is the sub I am using to open explorer...

sub ActivateIE                                                            objIE.Navigate path_html &"htmtest3.htm"                   
      Set IEWindow = objIE.Document.all("cont")                  
      objIE.ToolBar = false:objIE.StatusBar = False:objIE.Resizable = false
      objIE.document.frames("report").document.bgcolor = "transparent"
      objIE.document.title = "Logon Script"                        
      Do While objIE.Busy                                                 

      objIE.Width = 520:objIE.Height = 450                         
      objIE.Left = 50:objIE.Top = 50
      objIE.Visible = True

end sub
1 Solution
I believe there must be some way to prevent an IE window to be closed, because you can get the handle of the IE window by the hWND property. Then you can use some APIs to achieve your goal, but it's a little complicated.

I think the better solution is to put a WebBrowser control in a VB form, use that form instead of IE, then prevent users to close that VB window.

You can do it in VB quite easily:

Private Declare Function DeleteMenu Lib "user32" (ByVal hMenu As Long, ByVal nPosition As Long, ByVal wFlags As Long) As Long
Private Declare Function GetSystemMenu Lib "user32" (ByVal hWnd As Long, ByVal bRevert As Long) As Long
Private Const MF_BYPOSITION = &H400&
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long

Private Sub Form_Load()
    'Remove the close menu (which then disables the close button)
    RemoveClose "Google - Microsoft Internet Explorer"
End Sub

Private Sub RemoveClose(WindowName as String)
    Dim hMenu As Long, hWnd as Long
    hWnd = FindWindow(vbNullString, WindowName)
    hMenu = GetSystemMenu(hWnd, False)
    DeleteMenu hMenu, 6, MF_BYPOSITION
End Sub

However, in VBScript, I would think that it's impossible. And even if you disable the close button, people can still close the window with Ctrl-Alt-Del, Ctrl-F4, File->Close (Alt,F,C) or Alt-F4.
rosadoAuthor Commented:

I´ve found AutoItX3 which requires registering but works great by blocking keyboard and mouse...

PAQed with points refunded (500)

Community Support Moderator

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now