欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2022-08-27 16:34:33
winxp,win7,win8复制代码 代码如下:'原创内容转载、引用代码核心部分请注明出处硬盘读写统计.vbs if (lcase(right(wscript.fulln...

winxp,win7,win8

复制代码 代码如下:

'原创内容转载、引用代码核心部分请注明出处
硬盘读写统计.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
dim wmi,vname,ide,cppp,snow
input = 1:inputs = input*980
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 wscript.echo left(dskp0,1)&":"&vbtab& disk0 &vbtab _
                  &vbcrlf&vbtab&"厂商容量:"&round(size0/1000000000) &"gb" _
                  &vbcrlf&vbtab&"实际容量:"&round(size0/1073741824,2) &"gb" _
                  &vbcrlf&vbtab&"分区状态:"&right(dskp0,len(dskp0)-2)
if disk1 <> "" then wscript.echo left(dskp1,1)&":"&vbtab& disk1 &vbtab _
                  &vbcrlf&vbtab&"厂商容量:"&round(size1/1000000000) &"gb" _
                  &vbcrlf&vbtab&"实际容量:"&round(size1/1073741824,2) &"gb" _
                  &vbcrlf&vbtab&"分区状态:"&right(dskp1,len(dskp1)-2)
if disk2 <> "" then wscript.echo left(dskp2,1)&":"&vbtab& disk2 &vbtab _
                  &vbcrlf&vbtab&"厂商容量:"&round(size2/1000000000) &"gb" _
                  &vbcrlf&vbtab&"实际容量:"&round(size2/1073741824,2) &"gb" _
                  &vbcrlf&vbtab&"分区状态:"&right(dskp2,len(dskp2)-2)
if disk3 <> "" then wscript.echo left(dskp3,1)&":"&vbtab& disk3 &vbtab _
                  &vbcrlf&vbtab&"厂商容量:"&round(size3/1000000000) &"gb" _
                  &vbcrlf&vbtab&"实际容量:"&round(size3/1073741824,2) &"gb" _
                  &vbcrlf&vbtab&"分区状态:"&right(dskp3,len(dskp3)-2)
if disk4 <> "" then wscript.echo left(dskp4,1)&":"&vbtab& disk4 &vbtab _
                  &vbcrlf&vbtab&"厂商容量:"&round(size4/1000000000) &"gb" _
                  &vbcrlf&vbtab&"实际容量:"&round(size4/1073741824,2) &"gb" _
                  &vbcrlf&vbtab&"分区状态:"&right(dskp4,len(dskp4)-2)
if disk5 <> "" then wscript.echo left(dskp5,1)&":"&vbtab& disk5 &vbtab _
                  &vbcrlf&vbtab&"厂商容量:"&round(size5/1000000000) &"gb" _
                  &vbcrlf&vbtab&"实际容量:"&round(size5/1073741824,2) &"gb" _
                  &vbcrlf&vbtab&"分区状态:"&right(dskp5,len(dskp5)-2)
wscript.echo "↑请输入要监控的硬盘编号,并按回车键"
stdinput = wscript.stdin.readline
stdinput=left(ucase(stdinput),1)
if stdinput > "5" or stdinput < "0" then msgbox "输入错误" :wscript.quit
if instr(dskp0, stdinput) then call network(disk0,size0,dskp0)
if instr(dskp1, stdinput) then call network(disk1,size1,dskp1)
if instr(dskp2, stdinput) then call network(disk2,size2,dskp2)
if instr(dskp3, stdinput) then call network(disk3,size3,dskp3)
if instr(dskp4, stdinput) then call network(disk4,size4,dskp4)
if instr(dskp5, stdinput) then call network(disk5,size5,dskp5)

sub network(disks,sizes,dskps)
snow=now
do
dim a
'wscript.echo "已运行"&ts\3600&"小时"&(ts mod 3600)\60&"分钟"&(ts mod 3600) mod 60&"秒"
set a = wmi.execquery("select * from win32_perfrawdata_perfdisk_physicaldisk 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_physicaldisk where name='"&dskps&"'")
for each b in a
    r2 = b.diskreadbytespersec
    w2 = b.diskwritebytespersec
next
set a = nothing
wscript.echo disks &" " &round(sizes/1073741824) &"gb" &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


分区读写统计.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