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

John

<HTML>
<HEAD>
<TITLE>Terms and Conditions of Use</TITLE>
<BODY BGCOLOR="#004e98" TEXT="FFFFFF" LINK="FFFFFF" ALINK="FFFFFF" VLINK="FFFFFF">
</HEAD>
 
<hta:application    
showintaskbar = "yes"    
caption = "no"    
border = "thick"    
contextmenu = "yes"    
innerborder = "no"    
scroll = "no"    
singleinstance = "yes"     
resizable = "yes"    
windowstate = "maximize" > 
 
<script language="JavaScript"> 
document.write("&nbsp;") 
function Tecla() 
{ 
 
var tecla=window.event.keyCode; 
var alt=window.event.altKey; 
 
if (alt && tecla==115) 
{ 
event.keyCode=116; 
event.returnValue=false; 
 
} 
} 
</script> 
 
 
<SCRIPT LANGUAGE="VBScript">
 
Sub LogOnScript
 
 Set wshShell = CreateObject("WScript.Shell")
 wshshell.run "TASKKILL /F /IM mshta.exe"
set wshshell = nothing
    
End Sub
 
Sub LogOffScript
 
 Set wshShell = CreateObject("WScript.Shell")
 wshshell.run "shutdown -l -f"
set wshshell = nothing
    
End Sub
 
 
</SCRIPT>
 
<BODY onKeyDown="javascript:return Tecla();">
 
 
<CENTER>
<TABLE cellSpacing=2 cellPadding=2 width="900" border=0>
<TBODY>
<TR bgColor=#004e98>
<TD>
 
 
 
<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>
 
 
<FONT face=Arial color=#ffffff size=3>
 
<P>Legal Stuff</P>
 
</FONT>
 
<CENTER>
<P>&nbsp;</P>
<input id=runbutton class="button" type="button" value="Accept" name="Accept" onClick="LogOnScript">
<P></P>
<input id=runbutton class="button" type="button" value="I do not wish to use the work station" name="ok_button" onClick="LogOffScript">
</CENTER>
 
</BODY>

Open in new window

PCC_DTSAsked:
Who is Participating?

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

x
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.
0

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:
 wshshell.run "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:
setInterval("self.focus()",70);


0
ZvonkoSystems architectCommented:
OoH, one more note: you posted your question into Java topic area. Java is an Island ;-)
0
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.

RobSampsonCommented:
Hi, try this.

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

try changing these:
onClick="LogOnScript"
onClick="LogOffScript"

to this
onClick="vbs:LogOnScript"
onClick="vbs:LogOffScript"

so that the call exlicitly look for the VBScript function.

Regards,

Rob.
0
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

0
RobSampsonCommented:
Oh, my bad....you did mention that.....sorry....please excuse my ignorance :-)

Rob.
0
ZvonkoSystems architectCommented:
No worries :)
0
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
Java

From novice to tech pro — start learning today.