标题: [问题求助] VBS如何把这个结果写入文本文档,谢谢 [打印本页]
作者: czar8 时间: 2012-3-28 11:45 标题: VBS如何把这个结果写入文本文档,谢谢
本帖最后由 czar8 于 2012-3-28 17:31 编辑
本人想在cmd中获取网络流量,再执行相应的操作,批处理后台反复执行。
找了半天只找到了下面这个VBS脚本,执行结果看上去不错,但本人对VBS纯属文盲。想把它的结果写到c:\rece.txt中,9秒刷新写入一次。希望大伙给予帮助,谢谢。- ' *==============================================================================*
- ' * 网络流量统计.vbs By: FastSLZ 2009-1-28 首次发布与 bbs.bathome.cn *
- ' *==============================================================================*
- '特别提醒:本脚本必须在Administrator账户,且必须通过杀毒软件授权下才能正常运行!
- Dim WH
- Set WH = GetObject("Winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2").ExecQuery("Select * from Win32_DesktopMonitor")
- For Each aWH in WH
- TW = Int(aWH.ScreenWidth/8)
- Nexta
- Set WH = Nothing
- If TW <= 0 Then :TW =128 :End If
- If (Lcase(Right(Wscript.FullName,11)) = "wscript.exe") Then
- CreateObject("WScript.Shell").Run("%Comspec% /C " &Chr(34)&"mode con cols="& TW &"&Title 网络流量统计&&Cscript.exe //NoLogo "&Chr(34)& Wscript.ScriptFullName &Chr(34)&Chr(34)),3:Wscript.Quit
- End If
- Showy=vbCrLf & vbCrLf & vbCrLf & vbCrLf & vbCrLf
- Input=InputBox(Showy &"请输入刷新间隔时间(单位秒)"& vbCrLf &"间隔时间越长统计数据越精确", "BY: fastslz","2")
- Input=Int(Input)
- If Len(Input) = 0 Then:Input = 1:End If
- If Len(Input) >= 2 Then:WScript.Quit:End If
- InputS = Input*1000
- Dim WMI,Name
- Set WMI = GetObject("winmgmts:{impersonationLevel=impersonate}!\\.\root\cimv2")
-
- Set colItems = WMI.ExecQuery("Select * from Win32_NetworkAdapterConfiguration Where IPEnabled='TRUE'")
- For Each objItem In colItems
- Name = Replace(objItem.Description,"/","_")
- Next
- Set colItems = Nothing
- WScript.Echo "活动连接:"&Name
- If (IsArray(Name)) = TRUE Then:MsgBox vbTab& "貌似无任何网络" :WScript.Quit:End If
- Call Network(Name)
- Function Network(Names)
- Do
- Dim A
- Set A = WMI.ExecQuery("Select * from Win32_PerfRawData_Tcpip_NetworkInterface Where Name = '"& Name &"'")
- For Each B In A
- R1 = B.BytesReceivedPersec
- S1 = B.BytesSentPersec
- T1 = B.BytesTotalPersec
- If T0 ="" Then :T0 = B.BytesTotalPersec :End If
- Next
- Set A = Nothing
- WScript.Sleep(InputS)
- Set A = WMI.ExecQuery("Select * from Win32_PerfRawData_Tcpip_NetworkInterface Where Name = '"& Name &"'")
- For Each B In A
- R2 = B.BytesReceivedPersec
- S2 = B.BytesSentPersec
- T2 = B.BytesTotalPersec
- Next
- Set A = Nothing
- WScript.Echo "下载:" & CheckSize((R2-R1)/Input) &"/s" _
- &vbTab&"上传:" & CheckSize((S2-S1)/Input) &"/s" _
- &vbTab&"平均:" & CheckSize((T2-T1)/Input) &"/s" _
- &vbTab&"小计:" & CheckSize(T1-T0) _
- &vbTab&"累计:" & CheckSize(T1)
- Loop
- End Function
-
- Function CheckSize(SZ)
- On Error Resume Next
- If SZ => 1073741824 Then
- SZ = FormatNumber(SZ/1073741824) & " GB"
- ElseIf SZ => 1048576 Then
- SZ = FormatNumber(SZ/1048576) & " MB"
- ElseIf SZ => 1024 Then
- SZ = FormatNumber(SZ/1024) & " KB"
- Else
- SZ = SZ & " 字节"
- End If
- CheckSize=Right(" " & SZ,10)
- End Function
复制代码
作者: czar8 时间: 2012-3-28 11:54
vbs必须隐藏运行
最好是用批处理调用一次就获取一次流量即可
万分感谢
作者: find 时间: 2012-3-28 13:14
9秒刷新写入一次,是不是每次写入都覆盖以前的内容?
作者: czar8 时间: 2012-3-28 17:42
回复 3# find
不要覆盖,我的详细目的是用一个驻留后台的批处理统计10秒内总下载流量,如果分别超过自定范围(如3M),则执行注销命令。同时10写入一次流量到文本
作者: find 时间: 2012-3-28 22:30
test.bat- cscript //nologo C:\test.vbs >>C:\rece.txt
复制代码
作者: czar8 时间: 2012-3-28 22:50
回复 5# find
不懂啊,能不能帮我全部改一下,实现我上面的功能呀
欢迎光临 批处理之家 (http://bbs.bathome.net/) |
Powered by Discuz! 7.2 |