Skip navigation

Using a Web Form as an Input Screen

Downloads
43998.zip

\[Editor's Note: Share your scripting discoveries, comments, problems, solutions, and experiences with products. Email your contributions (500 words or less) to [email protected]. We edit submissions for style, grammar, and length. If we print your submission, you'll get $100.\]

I often use an input box to capture user input for one or two items in a script. I recently encountered a task that required input for several fields, including a password. I wanted to create a more user-friendly input form than the one I'd been using, and I wanted to mask the password input. Unfortunately, straight VBScript doesn't offer a simple solution.

I've dabbled with Web pages in the past and knew that a Web interface could provide a lot of functionality that VBScript doesn't offer. I decided to try merging VBScript with HTML. I researched HTML syntax and searched the Microsoft TechNet Script Center (http://www.microsoft.com/technet/scriptcenter/default.mspx) for help creating a simple, efficient solution.

I used Notepad and some rudimentary HTML to create a simple Web form. Listing 1 shows the code for this form. The form contains five fields: ServerName, UserID, Password, an OK button, and a hidden object type behind the OK button.

The WebIn2VB.vbs script, which Listing 2 shows, uses the computer name and user credentials that the Web input form captures. This script is just one example of how you can use the data. Alternatively, you might use the data you capture to pass credentials or to authenticate to a remote computer with credentials other than your own.

WebIn2VB.vbs creates an instance of Microsoft Internet Explorer (IE) and sets several form properties, such as position, width, and height. The script also turns off the menu and status bars to lock down the form. The script navigates (i.e., opens) the Web page and makes the page visible, thus presenting the input form to the user, as the code at callout A in Listing 2 shows.

As callout B in Listing 2 shows, the script uses a Do...Loop statement (often called a Do While loop) to enter a wait state that gives the user time to enter the data. When the user clicks the OK button, the OKClicked value changes; this action stops the Do While loop and proceeds with running the script. If the user clicks the X in the upper right corner to close the Web page, the script stops and the user receives an error message. If no other errors exist, the Web-form input values are available to the script and the IE instance closes.

The rest of WebIn2VB.vbs simply displays the values the user enters. In a real scenario, you'd include code that uses those values (e.g., code that collects information about a remote computer).

I didn't hard-code the .htm file's path in WebIn2VB.vbs. Therefore, you need to ensure that the script and .htm file are in the same folder before you use this script.

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish