|
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. Here I will
briefly show how to get a listing of each of the drives on your computer
and their free space.
The code below may look a little
complicated but that's only because it is script and HTML mixed
together, It' operation is really quite simple and you should examine it
in more detail for a better understanding of how it works.
Essentially, WSH is used to get the name
of your computer. Then WMI uses the Win32_LogicalDisk method to get
information about each of your drives. That's all there is to this
script. The rest id formatting.

You can download the file DF.hta (in a
zip file) by clicking here.
<html>
<head>
<title>Disk Free Space</title>
<HTA:APPLICATION ID="oHTA"
APPLICATIONNAME="DiskFreeSpace"
SINGLEINSTANCE="yes"
NAVIGABLE="yes"
>
<style>
body {
MARGIN-TOP: 0px;
MARGIN-BOTTOM: 0px;
MARGIN-RIGHT: 0px;
MARGIN-LEFT: 0px;
}
</style>
</head>
<body bgcolor="#ffffff">
<font size="2" face="Century Gothic, Tahoma, Arial,
Helvetica">
<script language="JavaScript">
<!--
if (window.resizeTo) self.resizeTo(600,400);
//-->
</script>
<script language="VBScript">
Set WshNetwork = CreateObject("WScript.Network")
HostName = WshNetwork.ComputerName
Set WshNetwork = Nothing
document.open
document.write "<p><h3 align=center><font color='black'
face='Century Gothic, Tahoma, Arial, Helvetica'>Disk
utilization on " & HostName & " </font></h3>"
document.write "<div align=right>© P. R. Sadowski
11/26/2001</div><hr size=1>"
document.close
</script>
<script language="VBScript">
on error resume next
document.open
document.writeln "<center><table border=1 bgcolor='white'>"
document.write "<tr><th bgcolor='lightblue'><font size='2'
face='Century Gothic, Tahoma, Arial, Helvetica'>Disk</th>"
document.write "<th bgcolor=lightblue><font size='2'
face='Century Gothic, Tahoma, Arial, Helvetica'>Volume
Name</th>"
document.write "<th bgcolor=lightblue><font size='2'
face='Century Gothic, Tahoma, Arial, Helvetica'>Total
Space</th>"
document.write "<th bgcolor=lightblue><font size='2'
face='Century Gothic, Tahoma, Arial, Helvetica'>Free Space</th>"
document.write "<th bgcolor=lightblue><font size='2'
face='Century Gothic, Tahoma, Arial, Helvetica'>FS Type</th>"
document.write "<th bgcolor=lightblue><font size='2'
face='Century Gothic, Tahoma, Arial, Helvetica'>Type</th></tr>"
for each Disk in getobject("winmgmts:{impersonationLevel=impersonate}").InstancesOf("Win32_LogicalDisk")
if disk.FileSystem then
document.write "<tr><td><font size='2' face='Century Gothic,
Tahoma, Arial, Helvetica'>" & Disk.Caption & "</td>"
document.write "<td><font size='2' face='Century Gothic,
Tahoma, Arial, Helvetica'>" & Disk.VolumeName & "</td>"
document.write "<td><font size='2' face='Century Gothic,
Tahoma, Arial, Helvetica'>" & FormatNumber(Disk.Size,0) &
"</td>"
document.write "<td><font size='2' face='Century Gothic,
Tahoma, Arial, Helvetica'>" &
FormatNumber(round((Disk.FreeSpace), 2),0)
document.write "<td><font size='2' face='Century Gothic,
Tahoma, Arial, Helvetica'>" & disk.FileSystem & "</td>"
document.write "<td><font size='2' face='Century Gothic,
Tahoma, Arial, Helvetica'>" & disk.Description & "</td></tr>"
end if
next
document.writeln "</table></center><br><br>"
document.close
</script>
</body>
</html>
|
|