Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Run file

Posted on 2008-11-01
5
Medium Priority
?
279 Views
Last Modified: 2010-04-24
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.
0
Comment
Question by:ankur3020
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 32

Accepted Solution

by:
Robberbaron (robr) earned 2000 total points
ID: 22875644
schedule this script to run every 15min

save file as checker.vbs or similar

Wscript.Timeout = 650  'seconds
 
Wscript.Echo "Script Start"
 
'get traffic in 10min
GetTraffic "localhost", bytesStart
Wscript.Sleep 600000   '10 minutes=600000 millisecs
GetTraffic "localhost", bytesEnd
 
If bytesEnd = bytesStart Then
  'no traffic
  KillProcess  "MyAppName"
  'start application
  
  Set WshShell = WScript.CreateObject("WScript.Shell")
  WshShell.Run "MyNextApp.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

0
 

Author Comment

by:ankur3020
ID: 22876818
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

0
 

Author Comment

by:ankur3020
ID: 22877989
i made the required changes and it is working fine now.thanks
0
 

Author Closing Comment

by:ankur3020
ID: 31512445
thks
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Recently I finished a vbscript that I thought I'd share.  It uses a text file with a list of server names to loop through and get various status reports, then writes them all into an Excel file.  Originally it was put together for our Altiris server…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question