Board logo

标题: 用VBS做磁盘空间查看脚本hta文本文件 [打印本页]

作者: Nickey     时间: 2007-10-7 20:58    标题: 用VBS做磁盘空间查看脚本hta文本文件

这个贴不知该在哪里发 既然有位仁兄已经发了一个代码编辑器的hta文件
我也将存放在网页里面多时的文件与大家分享
*注以下代码<hta......>有参考过其他作品的成分
将以下代码存为 *.hta 的形式
<html>
<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="JavaScript"><!--显示时间-->
function showClock() {}
function hideClock() {}
var timerRunning = false
function stopClock() {if(timerRunning) clearTimeout(timerID)}
function showTime() {
var now = new Date();
var year = now.getYear();
var month = now.getMonth() + 1;
var date = now.getDate();
var hours = now.getHours();
var mins = now.getMinutes();
var secs = now.getSeconds();
today=new Date();
if(today.getDay()==0) week="星期日"
if(today.getDay()==1) week="星期一"
if(today.getDay()==2) week="星期二"
if(today.getDay()==3) week="星期三"
if(today.getDay()==4) week="星期四"
if(today.getDay()==5) week="星期五"
if(today.getDay()==6) week="星期六"
var timeVal = year + "-" + month + "-" + date + "  ";
timeVal += ((hours < 10) ? "0" : "") + hours;
timeVal += ((mins < 10) ? ":0" : ":") + mins;
timeVal += ((secs < 10) ? ":0" : ":") + secs;
timeVal += "(" + week + ")";
lastVal = "<" + document.lastModified + ">";
document.Show.CLK1.value=timeVal; timerID=setTimeout("showTime()", 1000); timerRunning = true;
document.Show.CLK2.value=lastVal;
}
</Script>
<script language="vbscript"><!--分区情况列表-->
window.resizeTo 500, 410
  ileft = (window.screen.width-500)/2
  itop  = (window.screen.height-500)/2      
window.moveTo ileft,itop
     
Sub Window_onLoad
    GetDiskSpace
End Sub
Sub GetDiskSpace
Const HARD_DISK = 3
Const GB = 1073741824
strComputer = "."
Set objWMIService = GetObject("winmgmts:" + "{impersonationLevel=impersonate}!\\" + strComputer + "\root\cimv2")
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>" + "已用" + "</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><font color=000000>" + DeviceID                                  + "</font></td>"
    strHTML = strHTML + "<td width=110px align=center><font color=008040>" + FormatNumber(intTotalSpace,1,-1,-1,0)     + "</font></td>"
    strHTML = strHTML + "<td width=110px align=center><font color=ff0000>" + FormatNumber(infFuLin,1,-1,-1,0)          + "</font></td>"
    strHTML = strHTML + "<td width=110px align=center><font color=ba75ff>" + FormatNumber(intFreeSpace,1,-1,-1,0)      + "</font></td>"
    strHTML = strHTML + "<td width=110px align=center><font color=0080c0>" + FormatPercent(intFreeSpace/intTotalSpace) + "</font></td>"
Next
    strHTML = strHTML + "</table>"
DataArea.InnerHTML = strHTML
End Sub
Sub setx(t)
   dim obj : set 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
  Const StrCont = "<font size=2 COLOR='8000ff'>版本最后更新日期</font>"
  const StrMail = "<font size=2 COLOR='8000ff'>kanlis25@hotmail.com</font>"
  const Connect = "<font size=2 COLOR='8000ff'>http://hi.814e.com/kanlis</font>"  
</script>
</head>
<body onmouseover=showTime() bgcolor="acd6ff">
<p ALIGN="CENTER">
  <a href="http://hi.814e.com/kanlis/index.html">
   <span onmouseover=setx(Connect) onmouseout=setx('')>
    <font SIZE="4" color="e87400">【:::衰仔樂園:::】</font>
   </span>
  </a>
</p>
<font size="2">查看各分区磁盘使用情况(<font color="red">/GB</font>)</font>&nbsp;
  <span id="DataArea"></span>
  <form name="Show" onsubmit=0>
   <font style="color:gray" SIZE="2">
    <span onmouseover=setx(StrMail) onmouseout=setx('')>
     <INPUT SIZE="30" style="BACKGROUND-COLOR:#d6acff" ID="CLK1">
    </span>
    <span onmouseover=setx(StrCont) onmouseout=setx('')>
     <INPUT SIZE="30" style="BACKGROUND-COLOR:#d6acff" ID="CLK2">
    </span>
   </font>
  </form>
  <span style="color:darkblue" id="footer"></span>
</body>
</html>
[ Last edited by Nickey on 2007-10-8 at 01:32 PM ]
附件 1: 硬盘空间查看脚本.zip (2007-10-8 13:32, 1.97 K,下载次数: 23)

作者: wudixin96     时间: 2007-10-7 21:05
能不能规范点??用code包起来??
作者: tireless     时间: 2007-10-8 01:36
hta脚本挺好玩的 有界面
作者: wert123     时间: 2007-10-9 00:53
怎么不能查移动盘,怎么改下能查所有类型的盘?