快速业务通道

VBS 硬盘读写统计(分区读写统计)

作者 佚名 来源 ASP编程 浏览 发布时间 2013-07-09
区读写统计.vbs
复制代码 代码如下:

''原创内容转载、引用代码核心部分请注明出处
If (Lcase(Right(Wscript.FullName,11)) = "wscript.exe") Then
CreateObject("WScript.Shell").Run("%Comspec% /C " &Chr(34)&"mode con cols=52 lines=22" &"&Title 分区读写统计.vbs By: FastSLZ PCEVA Or BatHome &&Cscript.exe //NoLogo "&Chr(34)& Wscript.ScriptFullName &Chr(34)&Chr(34)),3:Set WMI = Nothing:Wscript.Quit
End If
Input = 1:InputS = Input*1000
Dim WMI,vName,IDE,cPPP,sNow
On Error Resume Next
Set WMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")

Set IDE = WMI.ExecQuery("Select * from Win32_DiskDrive WHERE InterfaceType=''IDE''")
Set cPPP = WMI.ExecQuery("SELECT * FROM Win32_PerfRawData_PerfDisk_PhysicalDisk WHERE Name<>''_Total''")
For Each oIDE In IDE
For i = 0 To IDE.Count
Select Case oIDE.Index
Case i
For Each oPPP In cPPP
If InStr(oPPP.Name, i) Then vName = oPPP.Name
Next
Select Case i
Case 0 Disk0=oIDE.Caption&" "&oIDE.FirmwareRevision:Size0=oIDE.Size:DskP0=vName
Case 1 Disk1=oIDE.Caption&" "&oIDE.FirmwareRevision:Size1=oIDE.Size:DskP1=vName
Case 2 Disk2=oIDE.Caption&" "&oIDE.FirmwareRevision:Size2=oIDE.Size:DskP2=vName
Case 3 Disk3=oIDE.Caption&" "&oIDE.FirmwareRevision:Size3=oIDE.Size:DskP3=vName
Case 4 Disk4=oIDE.Caption&" "&oIDE.FirmwareRevision:Size4=oIDE.Size:DskP4=vName
Case 5 Disk5=oIDE.Caption&" "&oIDE.FirmwareRevision:Size5=oIDE.Size:DskP5=vName
End Select

End Select
Next
Next
Set cPPP = Nothing:Set IDE= Nothing
If Disk0 <> "" Then DskP=Right(DskP0,Len(DskP0)-2):WScript.Echo Left(DskP0,1)&":"&vbTab& Disk0 &vbTab _
&vbCrLf&vbTab&"分区状态:"&Right(DskP0,Len(DskP0)-2)
If Disk1 <> "" Then DskP=DskP&" "&Right(DskP1,Len(DskP1)-2):WScript.Echo Left(DskP1,1)&":"&vbTab& Disk1 &vbTab _
&vbCrLf&vbTab&"分区状态:"&Right(DskP1,Len(DskP1)-2)
If Disk2 <> "" Then DskP=DskP&" "&Right(DskP2,Len(DskP2)-2):WScript.Echo Left(DskP2,1)&":"&vbTab& Disk2 &vbTab _
&vbCrLf&vbTab&"分区状态:"&Right(DskP2,Len(DskP2)-2)
If Disk3 <> "" Then DskP=DskP&" "&Right(DskP3,Len(DskP3)-2):WScript.Echo Left(DskP3,1)&":"&vbTab& Disk3 &vbTab _
&vbCrLf&vbTab&"分区状态:"&Right(DskP3,Len(DskP3)-2)
If Disk4 <> "" Then DskP=DskP&" "&Right(DskP4,Len(DskP4)-2):WScript.Echo Left(DskP4,1)&":"&vbTab& Disk4 &vbTab _
&vbCrLf&vbTab&"分区状态:"&Right(DskP4,Len(DskP4)-2)
If Disk5 <> "" Then DskP=DskP&" "&Right(DskP5,Len(DskP5)-2):WScript.Echo Left(DskP5,1)&":"&vbTab& Disk5 &vbTab _
&vbCrLf&vbTab&"分区状态:"&Right(DskP5,Len(DskP5)-2)
WScript.Echo vbCrLf&"请输入"&DskP&"中任意一个盘符"
stdInput = WScript.StdIn.Readline
stdInput=Left(UCase(stdInput),1)
If InStr(DskP,stdInput) Then Call Network(stdInput&":")
Sub Network(DskPs)
sNow=Now
Do
Dim A
Set A = WMI.ExecQuery("Select * from Win32_PerfRawData_PerfDisk_LogicalDisk Where Name = ''"& DskPs &"''")
For Each B In A
R1 = B.DiskReadBytesPersec
W1 = B.DiskWriteBytesPersec
If RA0 = "" Then RA0 = B.DiskReadBytesPersec Else RA1 = R1 End If
If WA0 = "" Then WA0 = B.DiskWriteBytesPersec Else WA1 = W1 End If
Next
Set A = Nothing
WScript.Sleep(InputS)
Set A = WMI.ExecQuery("Select * from Win32_PerfRawData_PerfDisk_LogicalDisk Where Name = ''"& DskPs &"''")
For Each B In A
R2 = B.DiskReadBytesPersec
W2 = B.DiskWriteBytesPersec
Next
Set A = Nothing
WScript.Echo "监控分区:" &DskPs &vbCrLf _
&"实时读取:" & CheckSize((R2-R1)/Input) &"/s" &vbCrLf _
&"实时写人:" & CheckSize((W2-W1)/Input) &"/s"&vbCrLf _
&"脚本累计读取:" & CheckSize(RA1-RA0) &vbCrLf _
&"脚本累计写入:" & CheckSize(WA1-WA0) &vbCrLf _
&"开机累计读取:" & CheckSize(R1) &vbCrLf _
&"开机累计写入:" & CheckSize(W1) &vbCrLf&vbCrLf&vbCrLf&vbCrLf&vbCrLf&vbCrLf&vbCrLf&vbCrLf&vbCrLf&vbCrLf&vbCrLf&vbCrLf&vbCrLf&vbCrLf _
&"已运行"&Ts\3600&"小时"&(Ts mod 3600)\60&"分钟"&(Ts mod 3600) mod 60&"秒"
Ts=DateDiff("s", sNow, Now)''Ts=TS+1
Loop
End Sub

Function CheckSize(SZ)
On Error Resume Next
If SZ => 1073741824 Then
SZ = FormatNumber(Round(SZ/1073741824,2))&" GB"
ElseIf SZ => 1048576 Then
SZ = FormatNumber(Round(SZ/1048576,2))&" MB"
ElseIf SZ => 1024 Then
SZ = FormatNumber(Round(SZ/1024,2))&" KB"
Else
SZ = "0"&FormatNumber(Round(SZ/1024,2)) & " KB"
End If
CheckSize=Right(" " & SZ,10)
End Function

凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢!

分享到: 更多

Copyright ©1999-2011 厦门凌众科技有限公司 厦门优通互联科技开发有限公司 All rights reserved

地址(ADD):厦门软件园二期望海路63号701E(东南融通旁) 邮编(ZIP):361008

电话:0592-5908028 传真:0592-5908039 咨询信箱:web@lingzhong.cn 咨询OICQ:173723134

《中华人民共和国增值电信业务经营许可证》闽B2-20100024  ICP备案:闽ICP备05037997号