首页 > Other > [推荐]磁盘空间查看HTA脚本(已更新)

[推荐]磁盘空间查看HTA脚本(已更新)

2006年10月1日

经过半个小时的研究和学习,碎片终于搞定了自己的第一个HTA脚本。虽然功能简单,但还是满有成就感的。有兴趣学习HTA的朋友可以去看碎片的译文

<html>

<!–  碎片于2006-10-1日编写完成!  –>
<!– 脚本已经更新一次,修正小数点前"0"的不正常显示 –>
<head>

<title>磁盘空间查看脚本</title>

<hta:application
    
applicationname="磁盘空间查看脚"    
    border
="dialog"
    borderstyle
="normal"
    caption
="yes"
    contextmenu
="no"
    maximizebutton
="no"
    minimizebutton
="yes"
    navigable
="no"
    scroll
="yes"
    selection
="no"
    showintaskbar
="yes"
    singleinstance
="yes"
    sysmenu
="yes"
    version
="1.0"
    windowstate
="normal"
>

<script language="vbscript">
<! Insert code, subroutines, and functions here –>
 window.resizeTo 
445265
      
Const strtime  = "<font size=2>1.1 (2006年10月1日)</font>"
      
const strmail  = "<font size=2>付 林 / fulin@winitcn.com</font>"
      
Sub Window_onLoad 
    GetDiskSpace 
End Sub

Sub GetDiskSpace
Const HARD_DISK = 3
Const GB = 1073741824

strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
    
& "{impersonationLevel=impersonate}!" & strComputer & "rootcimv2")
Set colDisks = objWMIService.ExecQuery _
    (
"Select * from Win32_LogicalDisk Where DriveType = " & HARD_DISK & "")
    strHTML 
= "<table border=’1′>"       
               strHTML 
= strHTML & "<tr>"
        strHTML 
= strHTML & "<td width=110px align=center><font size=2><b>" & "分区" & "</b></td>"
        strHTML 
= strHTML & "<td width=110px align=center><font size=2><b>" & "容量" & "</b></td>"
        strHTML 
= strHTML & "<td width=110px align=center><font size=2><b>" & "已用" &&
nbsp;
"</b></td>"
        strHTML 
= strHTML & "<td width=110px align=center><font size=2><b>" & "未用" & "</b></td>"
        strHTML 
= strHTML & "<td width=110px align=center><font size=2><b>" & "空闲" & "</b></td>"
    
    
For Each objDisk In colDisks    
intFreeSpace 
= objDisk.FreeSpace/GB
intTotalSpace 
= objDisk.Size/GB
pctFreeSpace 
= intFreeSpace/GB / intTotalSpace/GB
infFuLin 
= intTotalSpace-intFreeSpace
DeviceID 
= objDisk.DeviceID
        strHTML 
= strHTML & "<tr>"
        strHTML 
= strHTML & "<td width=110px align=center>" & DeviceID & "</td>"
        strHTML 
= strHTML & "<td width=110px align=center>" & FormatNumber(intTotalSpace,1,-1,-1,0& "</td>"
        strHTML 
= strHTML & "<td width=110px align=center><font color=#DB2C00>" & FormatNumber(infFuLin,1,-1,-1,0& "</td>"
        strHTML 
= strHTML & "<td width=110px align=center><font color=#008080>" & FormatNumber(intFreeSpace,1,-1,-1,0& "</td>"
        strHTML 
= strHTML & "<td width=110px align=center>" & FormatPercent(intFreeSpace/intTotalSpace) & "</td>"
  
Next
strHTML 
= strHTML & "</table>"
DataArea.InnerHTML 
= strHTML
 
End Sub
 
Sub setx(t)
   
dim obj : set&nb
sp;obj 
= window.event.srcElement
         
if t = "" Then
          obj.style.color  
= "gray"
          obj.style.cursor 
= "default"
       
Else
          obj.style.color  
= "darkblue"
          obj.style.cursor 
= "hand"
       
End if
        footer.innerHTML 
= t
end Sub
 
</script>
</head>

<body>
<!– HTML goes here –>
<font color="#C63358"><b>磁盘空间查看脚本</b></font><br>
    
<font size="2">显示各磁盘分区使用情况(<font color="#FF0000">/GB</font></font></font>
    
&nbsp;<font size="2"><style="text-decoration: none" href="http://www.mstc.com.cn/">技术中国</a><style="text-decoration: none" href="http://fulin.mstc.com.cn/">碎片技术日志</a></font>
    
<br>
<body bgcolor="#99CCFF">
    
<span id = "DataArea"></span>
        
<span style="color:gray">
      
<span onmouseover=setx(strtime) onmouseout=setx(”)><font size="2">版本</font></span><font size="2"> |
      
<span onmouseover=setx(strmail) onmouseout=setx(”)>作者</span> |</font>
    
</span>
    
<span style="color:darkblue" id="footer"></span>
</body>
</html>

注意:此脚本扩展名为.hta





声明  :  转载请注明出处: 碎片IT资讯





作者: 碎片 分类: Other 标签:
  1. axi
    2007年4月8日19:15 | #1

    增加一行 就可以取消右边的滚动条,但如果分区数多就不能显示,能否根据分区数的多少来自动调整窗体的高度(即 window.resizeTo 445, 265 中的 265 )呢?

  1. 本文目前尚无任何 trackbacks 和 pingbacks.