none
Auto focus HTA - works with XP but not Windows 7

    Question

  • Hi,

    I have developed an HTA splash screen that requires users to accept terms and conditions before proceeding.  For this to be effective, I need the hta to stay in front of all other open windows.  My code below works perfectly in Windows XP SP3, but not in Windows 7 (64-bit).

    I have stripped the relevent code down, and provided below.  Can anyone tell me why this will not work on my Win 7 PC?


    Thanks in advance!

    <html>
    <head>
    <title>Focus</title>
    <HTA:APPLICATION
         ID="objfocus"
         APPLICATIONNAME="Focus"
         SCROLL="auto"
         SINGLEINSTANCE="yes"
    >
    </head>

    <SCRIPT LANGUAGE="VBScript">

        Sub Window_OnLoad
            bringtofront
            iTimerID = window.setInterval("bringtofront", 1000)
        End Sub

        Sub bringtofront
       self.focus
        End Sub

    </SCRIPT>

    <body><span id = "ProcessList"></span>

    </body>
    </html>

    Friday, November 23, 2012 5:31 AM

Answers

All replies

  • Can't be done Vista and later.

    You can customize the GINA to do anything you want but you will need to hire a systems programmer or purchase a custom GINA from a third party.

    In XP Alt-F4 will quickly dismiss the HTA with no validation. Ctl-Alt-Del will allow a user to bypass the HTA. Most users know this as it has been posted all over the Internet for years.

    Only a change to the GINA can force a lock on the agreement page until the agreement is accepted.

    It is possible to run a stub program that switches to a new blank desktop that runs a modal dialog which will do the same thing without altering the GINA.  This can aslo be defeated but very few users will knwo how.

    All methods will work on Windows 7 but the GINA for WIndows 7 will be different.

    Many corporations use a custom GINA to perform variosu secondary checks and agreements.  Replacing the GINA is quite normal and is the preferred method of securing a logon.


    ¯\_(ツ)_/¯


    • Edited by jrv Friday, November 23, 2012 5:57 AM
    Friday, November 23, 2012 5:51 AM
  • Thanks for the response.  My full code has other controls in place to prevent ALT-F4, etc.  

    The scenario is a public kiosk using a guest domain account.   My desired approach was to have a vbs logon script (synchronous) that would call the HTA and would only continue after the hta was closed (i.e. loop until mshta.exe not detected).  We ran into problems with this though, because the hta was being terminated for some reason after 15 seconds.  So, as a workaround, the plan was to put the hta into HKLM/Run and add some additional controls (force focus, force recentre of window, prevent ALT-F4, etc).

    So, I'm in trouble it would seem.

    I either need a solution for the synchronous logon issue, or some other way to force the hta to remain in front of other windows.

    HELP!

    Friday, November 23, 2012 7:27 AM
  • Thanks for the response.  My full code has other controls in place to prevent ALT-F4, etc.  

    The scenario is a public kiosk using a guest domain account.   My desired approach was to have a vbs logon script (synchronous) that would call the HTA and would only continue after the hta was closed (i.e. loop until mshta.exe not detected).  We ran into problems with this though, because the hta was being terminated for some reason after 15 seconds.  So, as a workaround, the plan was to put the hta into HKLM/Run and add some additional controls (force focus, force recentre of window, prevent ALT-F4, etc).

    So, I'm in trouble it would seem.

    I either need a solution for the synchronous logon issue, or some other way to force the hta to remain in front of other windows.

    HELP!

    Don't care what controls you have in place the an HTA can still be very easily closed or bypassed.  Alt-Tab will always bypass it and you cannot trap these keys.

    What you are trying to do cannot be done.  Search this and other forums to see how this issue has ended for many other requests exactly like yours.

    What you are asking to do is not technically possible with WIndows NT.  It i used to work to some degree with W9x but NT does not6 let most proceszses force themselves to the top and you cannot disable or trap Ctl-Alt-Del.


    ¯\_(ツ)_/¯


    • Edited by jrv Friday, November 23, 2012 9:17 AM
    Friday, November 23, 2012 8:39 AM
  • Don't want to get off topic, but can't agree with "Alt-F4 will always bypass it and you cannot trap these keys"

    Code below works just fine to trap ALT-F4.

    <script language="vbscript">

    Sub KeyDown()
          '# MsgBox window.event.keyCode
          Select Case window.event.keyCode
              Case 115  'F4
              window.event.returnValue = false
                  window.event.keyCode = 0
              Case 116  'F5
                  window.event.returnValue = false
                  window.event.keyCode = 0
              Case 70   'Ctrl + F
                  If window.event.ctrlKey Then window.event.returnValue = false
              Case 27   'Escape
                  Window.Close()
          End Select
      End Sub

    Friday, November 23, 2012 8:51 AM
  • I said you cannot trap Ctl-Alt Del or Alt-Tab.  There are other things that cannot be trapped.

    Windows Vista and later will also not work as you want with an HTA.

    Sorry.


    ¯\_(ツ)_/¯


    • Edited by jrv Friday, November 23, 2012 9:02 AM
    Friday, November 23, 2012 8:57 AM
  • Sorry, you said QUOTE "Alt-F4 will always bypass it and you cannot trap these keys".

    Anyway, appreciate the input.  I'll think about other options.

    Friday, November 23, 2012 9:03 AM
  • Sorry, you said QUOTE "Alt-F4 will always bypass it and you cannot trap these keys".

    Anyway, appreciate the input.  I'll think about other options.

    Sorry - I fixed the text to say Alt-Tab.

    Here is the scritp I have used.  It is easy to insert.  I know how this does/doesn't work as I have used it for various things over the years.  It is easily bypassed and will not work at all in Vista and later.

    <script language="JavaScript"> 
    function document.onkeydown() {  
          var alt=window.event.altKey;
          if (event.keyCode==116 || event.keyCode==27 || alt && event.keyCode==115) {
               event.keyCode=0; 
               event.cancelBubble=true; 
               return false; 
          }
         } 
    </script>

    The Javascript method does not require an wireup.  It just hooks the document.


    ¯\_(ツ)_/¯

    Friday, November 23, 2012 9:21 AM
  • I would add that these kinds of things should be really hard to do (if not impossible) due to the potential for abuse. The following blog posting may prove helpful:

    How do I create a topmost window that is never covered by other topmost windows?

    Bill

    Friday, November 23, 2012 3:38 PM