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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ZvonkoSystems 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.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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 ;-)
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

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 :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.