Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 949
  • Last Modified:

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

0
PCC_DTS
Asked:
PCC_DTS
  • 5
  • 2
1 Solution
 
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
 
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 5
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now