Trying to run VBScript and JScript within a HTA page

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

Who is Participating?
ZvonkoConnect With a Mentor Systems architectCommented:
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.
ZvonkoSystems architectCommented:
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:

ZvonkoSystems architectCommented:
OoH, one more note: you posted your question into Java topic area. Java is an Island ;-)
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

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.


ZvonkoSystems architectCommented:
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

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

ZvonkoSystems architectCommented:
No worries :)
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.