Windows Scripting
  Home arrow Windows Scripting arrow Page 3 - HTML Applications: Giving WSH a User Inter...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Dedicated Servers 
Actuate Whitepapers 
VeriSign Whitepapers 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
WINDOWS SCRIPTING

HTML Applications: Giving WSH a User Interface
By: Nilpo
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 3
    2008-02-05

    Table of Contents:
  • HTML Applications: Giving WSH a User Interface
  • Creating your first HTA
  • Building the page
  • Taking it one step further

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    HTML Applications: Giving WSH a User Interface - Building the page


    (Page 3 of 4 )

     

    To begin with, we’re going to need some HTML for the page layout. This is pretty simple. I’m displaying a small form for the user to enter a hostname or IP address along with a button that will fire it off.

    <p><span class="title">Visual Ping Utility</span><hr><br>

        <p>Hostname: <input type="text" size="40" name="T1">

        <input type="submit" name="B1" value="Submit"></p>

    This is about as simple as you can get for a page. Be sure to place this code between the body tags. You’ll probably notice that I haven’t included an action for my form (or even the form element). This is because I’m not going to redirect anywhere. Instead, I’m going to build my script off of the button event instead.  You’ll see this later.

    <div id=Output></div>

    In the meantime, we need somewhere to put our output. An empty DIV will do nicely. Go ahead and place that directly under the last bit of HTML you just used.

    Now we can start building our script, but before we get too involved, let’s make sure that our window displays the size we want it to. Add the following script between the <head> and </head> tags.

    <script type="text/vbscript">

    Sub Window_OnLoad

       self.resizeTo 600, 400

    End Sub

    </script>

    The subroutine you’ve just added is what’s known as an event procedure. This is a procedure that executes in response to a specific event. Typically you would need to bind to its source; however, in this case it is available natively.

    The OnLoad event is fired by the Window object (browser window) whenever a page is fully loaded. In VBScript you denote an event procedure with the object_event naming convention. In this case, we’re telling the HTA to resize itself to 600 by 400 pixels once it has loaded. Be sure to use the <script> tag.  Remember, we’re building in HTML.

    Now we’ll add the rest of our script within the same <script> tag as well.

    Set WshShell = CreateObject("WScript.Shell")

    strOut=""

     

    Sub B1_onClick

       cmdarg="%comspec% /c ping.exe " & T1.value

       Set objExCmd = WshShell.Exec(cmdarg)

      

       strOut=objExCmd.StdOut.ReadAll

      

       Set regEx = New RegExp

       regEx.Pattern = "[fnrv]+"

       regEx.Global = True

       regEx.Multiline = True

       strOut = regEx.Replace(strOut, "<br>")

       Output.innerHTML= strOut

    End Sub

    Notice that I’ve used another event procedure. This one is attached to the button we added previously.  (Notice how I’ve used the element’s ID as the object). Here we’re just telling the HTA to execute this code any time that the button is clicked.

    The code is pretty simple. When it runs, it takes the value from the text box and issues it to the ping command. It then captures the output from the ping command and writes it dynamically inside of our empty DIV.

    The purpose of the regular expression is to take the ping output and reformat it as HTML. We’re just removing any line breaks and replacing them with HTML’s <br> tag.

    Save your file and give it a test run.  You should be able to enter a hostname or IP address and see the results back in the same window after pressing the button.

    More Windows Scripting Articles
    More By Nilpo


     

    WINDOWS SCRIPTING ARTICLES

    - Generating Outlook Signatures Based on Activ...
    - VBScript: Converting and Formatting with Fun...
    - VBScript: Conversion and Format Functions
    - VBScript: Array Functions
    - VBScript: Strings, You Can`t Function withou...
    - VBScript: More String Functions
    - VBScript: Functioning with Strings
    - Working with the Windows Registry in C++
    - Understanding Objects
    - HTML Applications: Giving WSH a User Interfa...
    - Modifying Computer Objects with Active Direc...
    - Logon Script to Send Email Notifications
    - Securing Computers and Active Directory
    - Moving and Renaming Computers with Active Di...
    - Working with System Processes in WSH





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway