Rob van der Woude's Scripting Pages

VBScript Scripting Techniques > HTAs


Consider HTAs (HTML Applications) webpages with access to local resources.

Though the engine that executes HTAs (MSHTA.EXE) is essentially the same as Internet Explorer, it doesn't have Internet Explorer's tight security restrictions.
In fact, if run with elevated privileges, HTAs have access to every resource that administrators have access to!

If you want to build a nice looking user interface for your VBScript scripts collection, try an HTA (or rewrite them in Visual Basic).
If you need to build a proof of concept for a new program, consider an HTA.

Visual Studio 2010 Express Installer screenshot

Microsoft's Visual Studio 2010 Express Edition installer is an example of a great looking HTA.

HTAEdit screenshot


On this page, I intend to show some of the pitfalls I encountered in building HTAs, and some solutions or work-arounds.

My preferred tools for developing HTAs are VBSEdit and HTAEdit (they come bundled, 32-bit and 64-bit VBSEdit and HTAEdit all in a single package).
Both come with built-in debugger, but debugging an HTA is much harder then debugging VBScript code, so I usually write and test VBScript code in VBSEdit, and when ready, use it in an HTA's subroutines.

HTAs aren't restricted to HTML and VBScript, you can use JScript and JavaScript without the need to install anything, and PerlScript if you install Perl.

Building Your HTA

Each HTA is actually an HTML page with one or more HTA specific code blocks.

Description Remarks
<!DOCTYPE HTML> Document Type Declaration Optional but recommended for IE versions > 6
<html lang="en"> HTML begin Language optional, <html> required
<head> HTML head begin Required
<title>My HTML application</title> HTML/HTA title bar caption Optional but recommended, will also show up in Windows' task bar
<HTA:APPLICATION HTA definition block begin Required
  APPLICATIONNAME="HTA Name" HTA name Required; can be read by script with HTAID.ApplicationName
  ID="HTAID" HTA unique ID Required
  VERSION="1.0" HTA version Required; can be read by script with HTAID.Version
  SINGLEINSTANCE="yes" Only one HTA with this HTA's ID can run at any time If omitted or "no", multiple instances of this HTA can run simultaneously
  WINDOWSTATE="maximize" Maximize the HTA window when opened Optional; not recommended if the HTA window must be resizable, as the window may resize spontaneously when dragged
/> HTA definition block end
</head> HTML head end Required
<script language="VBScript"> Unlike JavaScript in web pages, which is located inside the HTML head or inside the HTML body, the HTA's (VBScript) code is positioned between the HTML head and body
Sub Window_OnLoad
  'This method will be called
  'when the application loads
End Sub

Minimize and Maximize an HTA

page last uploaded: 2016-09-19, 14:58