PaulSadowski.com 

PaulSadowski.com
Tracert (traceroute) (HTA)
Sometimes you may want a graphical output of information or even of a text only command-line program's output. HTA files (HyperText Application) is a way to accomplish this.an HTA file uses script and HTML to display information in what is essentially a modified Internet Explorer Window. Using HTA you can utilize the features of WSH and WMI and more that aren't available to a normal HTML file with script. You can also have the script run command-line applications and display the output in a graphical window.

In the example below we run the command-line tracert.exe program to do a network path check to a remote host and capture the result, showing it in the window as below where it can be copied and pasted. This can be handy to have your clients use and send back results to you via email, for example. Once you write your HTA application, email it or put it on a web server for your clients to download and use.

This is meant for illustration. It is not a scripting tutorial so in brief the subroutine traceroute takes the hostname passed by the user through the HTA's form field and runs tracert.exe, a standard Windows command-line program. It captures the standard out (the text out of the program) and displays it in the HTA's window using DHTML. Since this window displays HTML the script uses the regular expression object to replace the DOS newlines with HTML line break characters '<br>'. That's all there is to it.

This can be a handy tool if you or your users aren't comfortable working from the command prompt.

This script requires a later version of the scripting host which includes the Exec method. See http://www.microsoft.com/scripting/ for more information.

You can download the file Trace.hta (in a zip file) by clicking here.

<html>
<head><title>Traceroute</title>
<HTA:APPLICATION ID="oHTA";
  APPLICATIONNAME="Traceroute";
  BORDER="thin";
  BORDERSTYLE="normal";
  SINGLEINSTANCE="no";
>
</head><body bgcolor="#E8E8E8" >
<font size=2 face="Century Gothic, Tahoma, Arial" color="black">
<script language="VBScript" type="text/vbscript">
set objShell = CreateObject("WScript.Shell")
strOut=""
sub traceroute
cmdarg="%comspec% /c tracert.exe " & T1.value
set objExCmd = objShell.Exec(cmdarg)
strOut=objExCmd.StdOut.ReadAll
Set regEx = New RegExp
regEx.Pattern = "[\f\n\r\v]+"
regEx.Global = True
regEx.Multiline = True
strOut = regEx.Replace(strOut, "<br>")
TraceOut.innerHTML= strOut
end sub
//-->
</script>
<p><b>Traceroute HTA by Paul R. Sadowski (11/2001)</b><hr noshode color="#000000"><br>
    <p>Hostname: <input type="text" size="40" name="T1">
    <input type="submit" name="B1" value="Submit"  onclick="traceroute"></p>
<div id=TraceOut></div>
<script language="JavaScript">
<!--
	if (window.resizeTo) self.resizeTo(600,400);
//-->
</script>
 

© 2001, 2005 by Paul R. Sadowski 
All Rights Reserved. Used By Permission.
Comments to: Scripting