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 <html> required, language (lang property) optional but recommended
<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
/> End of HTA definition block
</head> End of HTML head Required
<script language="VBScript"> WSH (VBScript) code begin Unlike JavaScript in web pages, which is located either inside the HTML head or inside the HTML body, the HTA's code (usually VBScript, but may also be JScript or PerlScript or any WSH supported scripting language) is positioned between the HTML head and body
Sub Window_OnLoad Use this code block to initialize objects and variables, parse the (optional) command line, etc.
  'This method will be called
  'when the application loads
End Sub
Sub Window_OnUnload Use this code block to clean up objects, close files, etc.
  'This method will be called
  'when the application exits
End Sub
</script> End of WSH (VBScript) code
<body> HTML body Use the HTML body to build the HTA's user interface
</html> End of file

Minimize and Maximize an HTA

page last uploaded: 2017-08-03, 12:02