[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
试试这样:
  1. '======================================================================
  2. '程序开始------检测迅雷是否运行-----是-----开始网络监视
  3. '                      |                        ↑
  4. '                      否                         |
  5. '                      |                        |
  6. '         ↑------ 一直监视系统进程-----迅雷运行---
  7. '         |              |
  8. '         ----------- 未运行
  9. '======================================================================
  10. On Error Resume Next
  11. Public CurrentFlowInt, ProFlag
  12. ConnectionID = "本地连接"
  13. Set ObjectNetwork = CreateObject("Wscript.Network")
  14. strComputer = ObjectNetwork.ComputerName
  15. '获取计算机名,必须用字符串,不能用.代替
  16. Set ObjectWSH = Wscript.createObject("Wscript.shell")
  17. Set ObjWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
  18. Set NetCards = ObjWMIService.ExecQuery("Select * from Win32_NetworkAdapter WHERE NetConnectionID='" & ConnectionID & "'")
  19. If NetCards.count<>0 Then
  20.         For Each NetCard In NetCards
  21.                 WScript.Echo "Name: " & NetCard.Name & "        MACAddress: " & NetCard.MACAddress
  22.                 NetCardName = NetCard.Name
  23.                 strNet = Split(NetCard.Name, " ", -1, 1)
  24.                 str1 = strNet(0) & strNet(1) '& strNet(2)
  25.         Next
  26.         Else
  27.         Wscript.Echo "网卡不存在."
  28.         WScript.Quit(0)
  29. End If
  30. '获取用于上网的网卡信息
  31. Set CheckProcess = ObjWMIService.ExecQuery("Select * from Win32_Process WHERE Name='Thunder.exe'")
  32. If CheckProcess.count<>0 Then
  33.         ProFlag = 0
  34.         Else
  35.         ProFlag = 1
  36. End If
  37. Set colMonitoredProcesses = objWMIService.ExecNotificationQuery("select * from __instancecreationevent " & " within 1 where TargetInstance isa 'Win32_Process'")
  38. i = 0
  39. Do While i = 0
  40.     Set CheckProcess = ObjWMIService.ExecQuery("Select * from Win32_Process WHERE Name='Thunder.exe'")
  41.         If CheckProcess.count<>0 Then
  42.                 Wscript.Echo "迅雷已运行."
  43.                 '监视网络
  44.                 CurrentFlow
  45.                 BeginFlow = CurrentFlowInt
  46.                 '获取开始时接收的流量(字节)
  47.                 Wscript.Echo "BeginFlow: " & BeginFlow
  48.                 WScript.Sleep 120000
  49.                 '定义时间范围
  50.         Else
  51.                 Wscript.Echo "迅雷未运行."
  52.                 Set objLatestProcess = colMonitoredProcesses.NextEvent
  53.                 '监视迅雷
  54.             If objLatestProcess.TargetInstance.Name = "Thunder.exe" Then
  55.                         Wscript.Echo "迅雷已运行."
  56.                         CurrentFlow
  57.                         BeginFlow = CurrentFlowInt
  58.                         '获取开始时接收的流量(字节)
  59.                         Wscript.Echo "BeginFlow: " & BeginFlow
  60.                         WScript.Sleep 120000
  61.                         '定义时间范围
  62.                 End If
  63.         End If
  64.         
  65.         CurrentFlow
  66.         EndFlow = CurrentFlowInt
  67.         '获取结束时接收的流量(字节)
  68.         Wscript.Echo "EndFlow: " & EndFlow
  69.         Result = EndFlow - BeginFlow
  70.         If Result<20480 Then
  71.                 '10240即10KB,当120000毫秒(120秒=2分钟)(上面的时间范围)内接收流量小于20KB就关闭系统
  72.                 WScript.Echo "关闭系统."
  73.                 ObjectWSH.Run"shutdown.exe -s -t 0", 0, TRUE
  74.         End If
  75.         '计算结果并比较
  76.         WScript.Echo "Exit ..."
  77.         WScript.Quit(0)
  78. Loop
  79. Function CurrentFlow
  80.         Set ObjectFlows = objWMIService.InstancesOf("Win32_PerfRawData_Tcpip_NetworkInterface")
  81.         For Each ObjectFlow In ObjectFlows
  82.                 strNetName = Split(ObjectFlow.Name, " ", -1, 1)
  83.                 str2 = strNetName(0) & strNetName(1) '& strNetName(2)
  84.                 If str1 = str2 Then
  85.                         CurrentFlowInt = ObjectFlow.BytesReceivedPersec
  86.                 End If
  87.         Next
  88. End Function
复制代码
1

评分人数

    • CrLf: 乐于助人技术 + 1
---学无止境---

TOP

回复 37# ygqiang


    36楼代码试试看?
---学无止境---

TOP

36楼代码,我这里是测试成功了。

你那没成功有没有提示什么?比如  这个提示BeginFlow:  后面有没有数字?
---学无止境---

TOP

返回列表