oracledba.help
Windows

HTML Applications (HTA)

Overview

Microsoft's HTML Applications (HTA) can be used to create GUI's for modest VBscript applications.

HTA Fun Facts

  • The HTML Application Host executable (mshta.exe) is part of the Windows OS.
  • HTAs use the Trident (MSHTML) browser engine used by Internet Explorer (IE).
  • HTAs are not dependent on the IE (unless you make ActiveX or related calls).
  • If IE is removed the MSHTML engine remains and HTAs continues to work.
  • HTAs work in Windows XP to Windows 11.

TOC

mshta.exe Paths

rem run32.bat
%WinDir%\SysWOW64\mshta.exe c:\page.hta

rem run64.bat
%WinDir%\System32\mshta.exe c:\page.hta

Useful Links

HTA:

VBScript:

Shortcut Example

C:\Windows\System32\cmd.exe /c "C:\app\hta\MyApp.bat"

Launcher (MyApp.bat)

 @echo off
 rem This line is useful when testing to clean up failed runs.
 Taskkill /IM mshta.exe /F

 rem Start App Minimized (resize from app)
 call start /min /b C:\app\hta\AyApp.hta
 exit

Windows 10 HTA Header

Gets around launching separate Browser window bug.

<!DOCTYPE HTML>
<html> 
<head>
   <title>MyApp</title>
   <HTA:APPLICATION
   APPLICATIONNAME="MyApp"
   ICON="display.ico"
   ID="this"
   NAVIGABLE="yes" 
   SCROLL="no"
   SINGLEINSTANCE="yes"
   VERSION="2.1"
   />
   </head>
   <script language="VBScript">
      Option Explicit
      const NORMAL_WINDOW = 1

      Sub Window_OnLoad
         rem  window.moveTo -2000,-2000
         window.resizeTo 1024, 600
         Call CenterWindow
         document.title = document.title
         window.focus
      End Sub

      sub Window_onUnload
         window.close()
      end sub

      Sub CenterWindow()
        Dim x, y
        With Window.Screen
          x = (.AvailWidth  - 1024 ) \ 2
          y = (.AvailHeight - 768 ) \ 2
        End With
        Window.MoveTo x, y
      End Sub        
   </script> 
</head> 
<body>
...

File Exentions, Associate with HTA

Open below displayed cmd windows As Administrator. The extention .h42 used in these examples. Change as required for your environment.

Add Association

 assoc .h42=mshta64
 ftype .h42=%WinDir%\System32\mshta.exe %1

View Associations: Via Cmd

 assoc > assoc.txt && notepad assoc.txt
 ftype > ftype.txt && notepad ftype.txt

View Associations: Via GUI

 Windows Server: Windows-Key, then type: File
 Windows 10\11: Windows-Key, then type: File Type Associations

Then select displayed item to set default app for file type. Syntax can vary.

Delete Association

 1. Run associated cmds for assoc & ftype:
    assoc .h42= 
    ftype .h42= 
    Make sure there is a space after the  equal signs.
 2. Delete sub key from registry (ex: .h42):
    HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts
    HKEY_CLASSES_ROOT
    Re-login to take effect.