Solved

Capture ALT+F4

Posted on 2011-09-12
4
1,514 Views
Last Modified: 2012-05-12
I have an hta that uses VBScript that cannot be closed by any other way except clicking on a button on the form. The problem is that it can also be exited by hitting Alt and F4. What I want is to either disable that (which I don't believe is possible using VBScript), or capturing Alt+F4 event in my VBScript code in order to perform other actions before closing the hta (the same thing as done with a button on the form). How can that be accomplished?
0
Comment
Question by:YZlat
  • 2
4 Comments
 
LVL 54

Expert Comment

by:Bill Prew
ID: 36525673
Some discussion of this here, and the linked solution, although it seems like jscript was needed as well.

http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_23881380.html

~bp
0
 
LVL 13

Accepted Solution

by:
Daz_1234 earned 500 total points
ID: 36528449
Hi YZlat,

In one of my HTA's I have the following VBScript sub:
  Sub KeyDown()
      '# MsgBox window.event.keyCode
      Select Case window.event.keyCode
          Case 115  'F4
              window.event.returnValue = false
              window.event.keyCode = 0
          Case 116  'F5
              window.event.returnValue = false
              window.event.keyCode = 0
          Case 70   'Ctrl + F
              If window.event.ctrlKey Then window.event.returnValue = false
          Case 27   'Escape
              Window.Close()
      End Select
  End Sub

Open in new window

... which when called from here:
<body onKeyDown='KeyDown()'>

Open in new window

... means that ALt-F4 is disabled (actually F4 is disabled whether or not you use ALT. If you wan't just Alt-F4 and not all F4 then let me know), F5 is disabled (refresh), CTRL+F is disabled (find) and the Escape key will close the application.

Hope this helps.
Daz.

0
 
LVL 35

Author Closing Comment

by:YZlat
ID: 36528999
Perfect! Thank you, it is just what I needed
0
 
LVL 13

Expert Comment

by:Daz_1234
ID: 36529010
You're welcome, cheers for the grade!

Daz.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
I met Paul Devereux (@pdevereux) today when I responded to his tweet asking “Anybody know how to automate adding files from disk to a folder in #outlook  ?”.  I replied back and told Paul that using automation, in this case scripting, to add files t…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

713 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question