MCSE技术论坛

首页 » 开发者俱乐部 » windows脚本 » 磁盘空间查看HTA脚本
洛洛 - 2007-4-13 15:15:00


<head>
<title>磁盘空间查看脚本</title>
<hta:application
applicationname=&quot;磁盘空间查看脚&quot;
border=&quot;dialog&quot;
borderstyle=&quot;normal&quot;
caption=&quot;yes&quot;
contextmenu=&quot;no&quot;
maximizebutton=&quot;no&quot;
minimizebutton=&quot;yes&quot;
navigable=&quot;no&quot;
scroll=&quot;yes&quot;
selection=&quot;no&quot;
showintaskbar=&quot;yes&quot;
singleinstance=&quot;yes&quot;
sysmenu=&quot;yes&quot;
version=&quot;1.0&quot;
windowstate=&quot;normal&quot;
>
<script language=&quot;vbscript&quot;>
<!-- Insert code, subroutines, and functions here -->
window.resizeTo 445, 265
      Const strtime  = &quot;<font size=2>1.0 (2007年02月14日)</font>&quot;
      const strmail  = &quot;<font size=2>洛洛 / lingluo18@gmail.com</font>&quot;
     
Sub Window_onLoad
    GetDiskSpace
End Sub

Sub GetDiskSpace
Const HARD_DISK = 3
Const GB = 1073741824
strComputer = &quot;.&quot;
Set objWMIService = GetObject(&quot;winmgmts:&quot; _
    &amp; &quot;{impersonationLevel=impersonate}!\\&quot; &amp; strComputer &amp; &quot;\root\cimv2&quot;)
Set colDisks = objWMIService.ExecQuery _
    (&quot;Select * from Win32_LogicalDisk Where DriveType = &quot; &amp; HARD_DISK &amp; &quot;&quot;)
    strHTML = &quot;<table border='1'>&quot;     
      strHTML = strHTML &amp; &quot;<tr>&quot;
        strHTML = strHTML &amp; &quot;<td width=110px align=center><font size=2><b>&quot; &amp; &quot;分区&quot; &amp; &quot;</b></td>&quot;
        strHTML = strHTML &amp; &quot;<td width=110px align=center><font size=2><b>&quot; &amp; &quot;容量&quot; &amp; &quot;</b></td>&quot;
        strHTML = strHTML &amp; &quot;<td width=110px align=center><font size=2><b>&quot; &amp; &quot;已用&quot; &amp; &quot;</b></td>&quot;
        strHTML = strHTML &amp; &quot;<td width=110px align=center><font size=2><b>&quot; &amp; &quot;未用&quot; &amp; &quot;</b></td>&quot;
        strHTML = strHTML &amp; &quot;<td width=110px align=center><font size=2><b>&quot; &amp; &quot;空闲&quot; &amp; &quot;</b></td>&quot;
   
   
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 &amp; &quot;<tr>&quot;
        strHTML = strHTML &amp; &quot;<td width=110px align=center>&quot; &amp; DeviceID &amp; &quot;</td>&quot;
        strHTML = strHTML &amp; &quot;<td width=110px align=center>&quot; &amp; FormatNumber(intTotalSpace,1) &amp; &quot;</td>&quot;
        strHTML = strHTML &amp; &quot;<td width=110px align=center><font color=#DB2C00>&quot; &amp; FormatNumber(infFuLin,1) &amp; &quot;</td>&quot;
        strHTML = strHTML &amp; &quot;<td width=110px align=center><font color=#008080>&quot; &amp; FormatNumber(intFreeSpace,1) &amp; &quot;</td>&quot;
        strHTML = strHTML &amp; &quot;<td width=110px align=center>&quot; &amp; FormatPercent(intFreeSpace/intTotalSpace) &amp; &quot;</td>&quot;
 
Next
strHTML = strHTML &amp; &quot;</table>&quot;
DataArea.InnerHTML = strHTML
End Sub

      Sub setx(t)
        dim obj : set obj = window.event.srcElement
        if t = &quot;&quot; then
          obj.style.color  = &quot;gray&quot;
          obj.style.cursor = &quot;default&quot;
        else
          obj.style.color  = &quot;darkblue&quot;
          obj.style.cursor = &quot;hand&quot;
        End if
        footer.innerHTML = t
      end Sub

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


注意:此脚本扩展名为.hta
1
查看完整版本: 磁盘空间查看HTA脚本