- StrComputer = "."
- ConnectionID = "本地连接1"
- '这里根据实际情况修改
-
- 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
- Next
- Else
- Wscript.Echo "网卡不存在."
- WScript.Quit(0)
- End If
- '获取用于上网的网卡信息
-
- CurrentFlow
- BeginFlow = CurrentFlow
- '获取开始时接收的流量(字节)
- Wscript.Echo "BeginFlow: " & BeginFlow
-
- WScript.Sleep 18000
- '定义时间范围
-
- CurrentFlow
- EndFlow = CurrentFlow
- '获取结束时接收的流量(字节)
- Wscript.Echo "EndFlow: " & EndFlow
-
- Result = EndFlow-BeginFlow
- If Result<10240 Then
- '10240即10KB,当18000秒(上面的时间范围)内接收流量小于10KB就关闭系统
- WScript.Echo "关闭系统."
- ObjectWSH.Run"shutdown.exe -s -t 0", 0, TRUE
- End If
- '计算结果并比较
-
- WScript.Echo "Exit..."
- WScript.Sleep 10000
-
-
- Function CurrentFlow
- Set ObjectFlows = ObjectWMI.InstancesOf("Win32_PerfRawData_Tcpip_NetworkInterface")
- For Each ObjectFlow In ObjectFlows
- If ObjectFlow.Name=NetCardName Then
- CurrentFlow = ObjectFlow.BytesReceivedPersec
- End If
- Next
- End Function
复制代码
|