- On Error Resume Next
- Public CurrentFlowInt
- StrComputer = "."
- ConnectionID = "本地连接"
- '这里根据实际情况修改
-
-
- Set objWMIService = GetObject("winmgmts:" _
- & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
- Set colMonitoredProcesses = objWMIService. _
- ExecNotificationQuery("select * from __instancecreationevent " _
- & " within 1 where TargetInstance isa 'Win32_Process'")
- i = 0
- Do While i = 0
- Set objLatestProcess = colMonitoredProcesses.NextEvent
- If objLatestProcess.TargetInstance.Name = "Thunder.exe" Then
- Wscript.Echo "迅雷已运行."
-
- Set ObjectWSH = CreateObject("Wscript.Shell")
- Set ObjectWMI = Getobject("winmgmts:\\" & StrComputer)
-
- Set NetCards = ObjectWMI.ExecQuery("Select * from Win32_NetworkAdapter WHERE NetConnectionID='" & ConnectionID & "'")
- If NetCards.count<>0 Then
- For Each NetCard In NetCards
- WScript.Echo "Name: " & NetCard.Name & " MACAddress: " & NetCard.MACAddress
- NetCardName = NetCard.Name
- strNet = Split(NetCard.Name, " ", -1, 1)
- str1 = strNet(0) & strNet(1) & strNet(2)
- Next
- Else
- Wscript.Echo "网卡不存在."
- WScript.Quit(0)
- End If
- '获取用于上网的网卡信息
-
- CurrentFlow
- BeginFlow = CurrentFlowInt
- '获取开始时接收的流量(字节)
- Wscript.Echo "BeginFlow: " & BeginFlow
-
- WScript.Sleep 120000
- '定义时间范围
-
- CurrentFlow
- EndFlow = CurrentFlowInt
- '获取结束时接收的流量(字节)
- Wscript.Echo "EndFlow: " & EndFlow
-
- Result = EndFlow-BeginFlow
- If Result<10240 Then
- '10240即10KB,当120000毫秒(120秒=2分钟)(上面的时间范围)内接收流量小于10KB就关闭系统
- WScript.Echo "关闭系统."
- ObjectWSH.Run"shutdown.exe -s -t 0", 0, TRUE
- End If
- '计算结果并比较
-
- WScript.Echo "Exit..."
- WScript.Sleep 10000
- WScript.Quit(0)
- End If
- Loop
-
-
- Function CurrentFlow
- Set ObjectFlows = ObjectWMI.InstancesOf("Win32_PerfRawData_Tcpip_NetworkInterface")
- For Each ObjectFlow In ObjectFlows
- strNetName = Split(ObjectFlow.Name, " ", -1, 1)
- str2 = strNetName(0) & strNetName(1) & strNetName(2)
- If str1 = str2 Then
- CurrentFlowInt = ObjectFlow.BytesReceivedPersec
- End If
- Next
- End Function
复制代码 这个代码,属于测试代码,时间间隔设置成2分钟,会陆续弹出相关窗口。
遇到的问题是:
xp sp3系统下,
如果vbs代码先启动,再启动迅雷7的话,测试正常(弹出窗口,可以自动关机)。
如果迅雷7先启动,再运行这个vbs代码,测试无反映(不弹出窗口,不自动关机)。 |