title: prevent user closing a HTA
body: <p>Using vbscript in a HTA</p>
  
  <p>Aim: To prevent a user closing the HTA (except by my custom button or by using windows taskmanager)</p>
  
  <p>As i understand from various webpages; You cannot prevent the HTA from closing when the close button is clicked in the HTA SYSMENU. Therefore my solution is to prevent the user from clicking close in the first place.</p>
  
  <p>First up is to disable the system menu:</p>
  
  <pre><code>&lt;HTA:APPLICATION SYSMENU="no" /&gt;
  </code></pre>
  
  <p>nb. I will replace the system menu with a custom one - any links to a good guide for this would be appreciated.</p>
  
  <p>Next prevent keyboard shortcuts alt+f4, f5, or escape as follows:</p>
  
  <pre><code>Function Document_onKeyDown()
  
      Dim alt
      alt = window.event.altKey
      Select Case window.event.keyCode
          Case 27,116
              window.event.keyCode = 0
              window.event.cancelBubble = true
              Document_onKeyDown = False
          Case 115
              If alt Then
                  window.event.keyCode = 0
                  window.event.cancelBubble = true
                  Document_onKeyDown = False
              End If
          Case Else
              Document_onKeyDown = True
      End Select
  
  End Function
  </code></pre>
  
  <p>Finally I want to prevent the user using the windows taskbar context menu for my HTA app.</p>
  
  <p>How can I prevent the user from seeing a context menu by right clicking my HTA?</p>
  
  <p>nb. The HTA window cannot be full screen</p>