When you need to create input forms, HTML Applications (HTAs) can be a near-perfect solution, as I explain in "Hooked on HTAs," August 2005, InstantDoc ID 46795. With just a little practice, you can create HTAs like the one I'm going to show you. This fully functional sample form, which I've named User Quota Utility, lets you set and display disk quotas on local and remote Windows Server 2003 and Windows XP computers. Even if you don't use quotas, this form is a useful example of how to develop administrative utilities by using an HTA and VBScript. If you use Windows 2003 or XP but haven't enabled quotas, you can do so (by using the Properties dialog box) on a local disk so that you can try out this sample HTA. In that situation, don't select the Deny disk space to users exceeding quota limit check box. If you select that check box, you might accidentally deny a user the ability to write to disk if the quota is exceeded. (For information about using quotas, see the Microsoft article "Managing Disk Quotas in Windows Server 2003 and Windows XP" at http://www.microsoft.com/technet/scriptcenter/topics/win2003/quotas.mspx.)
The HTA at a Glance Figure 1 shows User Quota Utility: an input screen that consists of four input fields, one drop-down box, two buttons, and two text boxes. Let's take a look at these components and at how the utility works.
The input boxes. The first input box lets the user enter a list of user IDs for the user accounts that require quota changes. In the second input box, the user enters the name of the server or computer on which the quotas reside. (If this field is left blank, the utility defaults to the local machine.) If the specified user IDs are domain accounts or accounts on another computer, the user needs to enter the domain or computer name in the third input box. (If this field is left blank, the utility again defaults to the local system.)
In the fourth input box, the user enters the quota size, in bytes. As you can see in Figure 1, I've hard-coded in a default of 5368709120, or 5GB, but you can easily modify that number. In the event that you prefer to give users a choice of entering this data in bytes, megabytes, or gigabytes, I created a second HTA (UserQuotaUtility2.hta) that provides all three options, as Figure 2 shows.
The drop-down box. The drop-down box, located directly after the second text box, lets the user select the drive letter of the computer on which the quotas reside. The drop-down box in this sample HTA uses a pretty lengthy list of drive letters. I've set the default value to the C: drive.
The buttons. When the user clicks the first button, labeled Run Modify User Quotas, User Quota Utility attempts to set the specified quota on the chosen systems. This action is associated with the RunMod subroutine in the HTA's VBScript section, which Listing 1 shows.
The second button, labeled Run Quota Query, lists quota information for a specific server and drive. This action is associated with the RunQuery subroutine in the HTA's VBScript section. The application doesn't filter user IDs when running this subroutine; instead, it lists all user quota settings for the specified computer and drive. Even when the user has listed user IDs in the first input box, clicking the Run Quota Query button will return information about all accounts on the specified system, not just the listed accounts.
The text boxes. The first text box, labeled Status Box, displays the status (i.e., successful or unsuccessful) of the most recent action. The second text box, labeled Application Information, is a summary of the application, including some instruction. These two boxes are the same types of text boxes that the utility uses for input but are declared ReadOnly, which prevents users from entering text. (You can programmatically change the contents of these text areas by assigning a different value to the fieldnames.value code in the HTA script.)
Inside the HTA
The HTA starts with the basic HTA application settings (see "Hooked on HTAs" for details about the available settings). The entire HTA is too long to print, but you can download the file (UserQuotaUtility.hta) from the Windows Scripting Solutions Web site. (Go to http://www.windowsitpro.com/windowsscripting, enter 47101 in the InstantDoc ID text box, then click the 47101.zip hotlink; the .zip file also includes UserQuotaUtility2.hta.) To view the script, open the HTA file in Notepad.
After the application settings, the HTA includes the VBScript section, which Listing 1 shows. This section contains three subroutines: Window_Onload, RunMod, and RunQuery.
Window_Onload. The Window_Onload subroutine executes automatically when the application is launched. First, the subroutine uses self.Focus() to launch the application window in front of any other open windows. The subroutine then sizes the application window and sets the default quota size (qlimit.value).
Master SharePoint with 3 eLearning Seminars Learn how to build a better SharePoint infrastructure and enable powerful collaboration with MVPs Dan Holme and Michael Noel. Register today!
SharePointConnections Conference Fall 2008 Don’t miss the premier event for Microsoft IT Professionals in Las Vegas, November 10-13. Register and book your room by August 25 and receive a FREE room night (based on a three night minimum stay).
VMworld 2008 - Sign Up Today! Join your peers on September 15-18 at The Venetian Hotel in Las Vegas as VMware hosts VMworld 2008, the leading Virtualization event.
Microsoft® Tech•Ed EMEA 2008 IT Professionals Advance your thinking with new ideas and practical real-world solutions at Microsoft’s FIVE day technical infrastructure conference 3-7 Nov., 2008. Register before 26 September 2008 to save €300.
Order Your SQL Fundamentals CD Today! Learn how to use SQL Server, understand Office integration techniques and dive into the essentials of SQL Express and Visual Basic with this free SQL Fundamentals CD.
Are You Really Compliant with Software Regulations? View this web seminar that will help you with compliance best practices and check out a management solution to assure that you won’t be in jeopardy of an audit.