Trying to run VBScript and JScript within a HTA page

Posted on 2008-11-06
Last Modified: 2011-09-20
Hi Experts,

I am currently working on a project to update all of the public access machines for a local authority.  At the moment there is a mixture of configurations, lockdowns and applications all stuck together in a massive workgroup.  The plan is to provide a consistent environment throughout the city on all machines.  

To prevent the public being given passwords the staff member in charge will log the users onto a workstation via a central machine.

As part of the login process users have to agree to our terms and conditions, if they do not agree the session will end and the user logged off.  If they press agree they are able to access the desktop.

As it currently stands I have developed an HTA page that runs in full screen blocking the desktop from view.   The terms and conditions are displayed the option to Accept or End Session are given.  I have got this working through VBScript.  My problem is that a user can press ALT + F4 and close the window.

I have found some Jscript code through Google that has solved the ALT + F4 problem, but now the VBScript no longer works!

I have included the HTA script and hopefully someone will either spot what I have done wrong or be able to provide some suitable Jscript to replace the VBScript.

Thanks for your help




<TITLE>Terms and Conditions of Use</TITLE>




showintaskbar = "yes"    

caption = "no"    

border = "thick"    

contextmenu = "yes"    

innerborder = "no"    

scroll = "no"    

singleinstance = "yes"     

resizable = "yes"    

windowstate = "maximize" > 

<script language="JavaScript"> 


function Tecla() 


var tecla=window.event.keyCode; 

var alt=window.event.altKey; 

if (alt && tecla==115) 








Sub LogOnScript

 Set wshShell = CreateObject("WScript.Shell") "TASKKILL /F /IM mshta.exe"

set wshshell = nothing


End Sub

Sub LogOffScript

 Set wshShell = CreateObject("WScript.Shell") "shutdown -l -f"

set wshshell = nothing


End Sub


<BODY onKeyDown="javascript:return Tecla();">


<TABLE cellSpacing=2 cellPadding=2 width="900" border=0>


<TR bgColor=#004e98>


<CENTER> <IMG src="Logo.jpg"></CENTER>

<FONT face=Arial color=#ffffff size=5>

<P Align="Center"><B>Terms and Conditions of Use</B></P>


<FONT face=Arial color=#ffffff size=3>

<P>Legal Stuff</P>




<input id=runbutton class="button" type="button" value="Accept" name="Accept" onClick="LogOnScript">


<input id=runbutton class="button" type="button" value="I do not wish to use the work station" name="ok_button" onClick="LogOffScript">



Open in new window

Question by:PCC_DTS
    LVL 63

    Accepted Solution

    Either change the order of script sections to section with vbscript to be the first script section or prefix the vent handler calls in input tags with the vbscript: prefix

    But you have one more problem: keep hta be focused when alt-tab is pressed.
    LVL 63

    Expert Comment

    OK, two additions to your code:

    1.) Add a second parameter to your Run calls: "TASKKILL /F /IM mshta.exe", 0

    That will suppress the DOS window popups.

    2.) Add the keepFocus line where your unneccessary document.write() is.
    Like this:

    LVL 63

    Expert Comment

    OoH, one more note: you posted your question into Java topic area. Java is an Island ;-)
    LVL 65

    Expert Comment

    Hi, try this.

    The same way that you have:
    onKeyDown="javascript:return Tecla();"

    try changing these:

    to this

    so that the call exlicitly look for the VBScript function.


    LVL 63

    Expert Comment

    It seams my first comment was not readable to all.
    Therefore here my proposal from first comment:
    <input id=runbutton class="button" type="button" value="Accept" name="Accept" onClick="vbscript:LogOnScript">

    Open in new window

    LVL 65

    Expert Comment

    Oh, my did mention that.....sorry....please excuse my ignorance :-)

    LVL 63

    Expert Comment

    No worries :)

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
    In Part 1 ( we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    728 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

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now