Link to home
Start Free TrialLog in
Avatar of ankur3020
ankur3020

asked on

Run file

vbs code that do the following.

1. check whether any data is received by lan /network or not
2. if not data received for last 10 mintues, terminate specified process.
3. run specified program
4. loop repeats after every 15 minutes.
ASKER CERTIFIED SOLUTION
Avatar of Robberbaron (robr)
Robberbaron (robr)
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ankur3020
ankur3020

ASKER

i ran the code and found one error. plsrectify it. the code i used is attached for ur ref.
i got error in line 12, killprocess,  error is invalid property /argument.
 pls tell me what is meaning of timeout, and for how long script will run.

i have replaced the process name with my actual process. one thing i want to know that r u comparing value or data received at different times or data sent.
Wscript.Timeout = 650  'seconds
 
Wscript.Echo "Script Start"
 
'get traffic in 10min
GetTraffic "localhost", bytesStart
Wscript.Sleep 600   '10 minutes=600000 millisecs
GetTraffic "localhost", bytesEnd
 
If bytesEnd = bytesStart Then
  'no traffic
  KillProcess  "BBClient.exe"
  
  'start application
  
  Set WshShell = WScript.CreateObject("WScript.Shell")
  WshShell.Run "BBClient.exe"
 
End if
 
WScript.quit
 
Sub KillProcess(strComputername,processName)
	strComputer = strComputername  '"."
	Set objWMIService = GetObject("winmgmts:" _
	    & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
	Set colProcessList = objWMIService.ExecQuery _
	    ("SELECT * FROM Win32_Process WHERE Name = '" & processName & "'")
	For Each objProcess in colProcessList
	    objProcess.Terminate()
	Next
End Sub
 
Sub GetTraffic(strComputername,bytesTotal)
  'List the network interfaces on the computer. These can be used to find the packets and network traffic
  Dim oSvc
  set oSvc = GetObject("winmgmts:\\" & strComputername & "\root\cimv2")
  wqlQuery = "Select * from Win32_PerfRawData_Tcpip_NetworkInterface"
  bytesTotal=0
  for each oData in oSvc.ExecQuery(wqlQuery)
    
    for Each oProperty in oData.Properties_
 
      if oProperty.Name = "BytesReceivedPersec" then
        
        bytesTotal = oProperty.Value
 
      end if      
    next
  next
 
End Sub

Open in new window

i made the required changes and it is working fine now.thanks
thks