Shutdown when downloads stop.

willemvdm

Well-Known Member
Joined
Apr 16, 2006
Messages
338
Reaction score
0
Location
Uitenhage
I'm looking for a little free app that will monitor bandwidth usage and shutdown my PC when usage go below x for a certain period. I'd rather have my PC shut down when the line gets throttled/shaped instead of it working all night/day with very little to show.

I've got an autoit script that I used to use, but it no longer work in windows 7. Any suggestions please. Even if it just sound an alarm, it will also do, but I'd prefer a shutdown.

Thanks.
 
Last edited:
I'm looking for a little free app that will monitor bandwidth usage and shutdown my PC when usage go below x for a certain period. I'd rather have my PC shut down when the line gets throttled/shaped instead of it working all night/day with very little to show.

I've got an autoit script that I used to use, but it no longer work in windows 7. Any suggestions please. Even if it just sound an alarm, it will also do, but I'd prefer a shutdown.

Thanks.

Maybe share the script with us and have you tried the script with AutoIt v3?
 
Note the script was not meant as an accurate Bandwidth monitor, however it does the job of shutting down when line is not active enough. Worked well for me in Windows XP, but no longer work in Win 7. Please don't ask me exactly how and what each line of code do, cause most of the code I copied out of other bandwidth monitoring scripts that I found on the internet. If anyone know how to modify the script so that it will work with windows 7 or know of a ready to use free application on the net that I could download, it would be much appreciated.

Code:
#include <WindowsConstants.au3>
#include <ProgressConstants.au3>
#include <GUIConstantsEx.au3>

const $wbemFlagReturnImmediately = 0x10
const $wbemFlagForwardOnly = 0x20
const $size = 150
const $delay = 1
const $InactiveTime = 300   ;Was 900
const $BellTime = 36
$TTS = 0
dim $data[$size+1]
$colItems = ""
$strComputer = "localhost"
$objWMIService = ObjGet("winmgmts:\\" & $strComputer & "\root\CIMV2")

func _GetBW() 
	$colItems = $objWMIService.ExecQuery("SELECT BytesReceivedPersec,BytesSentPersec FROM Win32_PerfRawData_Tcpip_NetworkInterface", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
   
	If IsObj($colItems) then
		For $objItem In $colItems
			$newin = $objItem.BytesReceivedPersec
			$newout = $objItem.BytesSentPersec
		Next
	EndIf
	Return $Newout + $newin
EndFunc


$Startval = _GetBW()
for $i = 0 to $size  
	$data[$i] = $Startval
Next

GUICreate("Bandwidth Monitor",220,130,0,0,-1,BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW))
$label1 = GUICtrlCreateLabel ( "Waiting for data...", 10, 5,200,20)
$progressbar1 = GUICtrlCreateProgress (10,20,200,20,$PBS_SMOOTH)
GUICtrlSetColor($progressbar1, 0xff0000) 
$label2 = GUICtrlCreateLabel ( "Waiting for data...", 10, 50,200,20)
$progressbar2 = GUICtrlCreateProgress (10,65,200,20,$PBS_SMOOTH)
$InactiveShutDown = GUICtrlCreateCheckbox("Hibernate", 10, 90)
$InputCutOff = GUICtrlCreateInput ( 5, 100, 90 , 30, 20)
GUISetState ()
$tm = 0

while 1 
	sleep ($delay*1000-50)
	$Cutoff = GUICtrlRead ($InputCutOff)
	for $i = $size to 1 step -1
		$data[$i] = $data[$i-1]
	Next
	if $tm<$size then $tm += 1
	$data[0] = _GetBW()
	GUICtrlSetData ($progressbar1,($data[0]-$data[$size])/$tm/512/$delay)
    GUICtrlSetData ($label1, int($tm/$size*100) & "%" & "          " & round(($data[0]-$data[$size])/$tm/1024/$delay,2))
	GUICtrlSetData ($progressbar2,($data[0]-$data[1])/512/$delay)
    GUICtrlSetData ($label2, int($TTS/$InactiveTime*100) & "%" & "          " & round(($data[0]-$data[1])/1024/$delay,2))
	if ($data[0]-$data[$size])/$tm/1024/$delay < $Cutoff and GUICtrlRead ( $InactiveShutDown ) = $GUI_CHECKED then 
		$TTS += 1
		if mod($TTS,$BellTime)=0 Then SoundPlay(@WindowsDir & "\media\Windows Notify.wav")
		if $TTS > $InactiveTime Then
			$m = MsgBox(1,"Shutdown","Hibernating in 15 seconds",15)
			if $m = 2 then 
				$TTS = 0
			Else
				Shutdown(64)
				Exit
			EndIf
		EndIf
	Else
		$TTS = 0
	EndIf	
	for $j = 1 to 10 
		if GUIGetMsg() = $GUI_EVENT_CLOSE then Exit
		Next
WEnd
 
I'll take a look at the code when I do have time, could be a few variables in terms of directories/files that have changed between XP and 7.

Edit: @willemvdm, I would recommend posting your problem in the AutoIt forums. From what I can see it's a few things that just need renaming but I don't want to misform you which could just lead you in circles.

I reckon they will be able provide more sound advice to your problem.

http://www.autoitscript.com/forum/index.php?showforum=2
 
Last edited:
Thanks DJNgoma,

I can't register on that forum. Register button keep on sending me to the read only portion of the site, though that little block thing is green, so I'm suppose to be able to use the proper site.

However I did some more digging and found a solution to my problem. It is probably not the best or correct way to code this, but it is now working for me. I just added a ExitLoop into the GetBW function.

Code:
func _GetBW() 
	$colItems = $objWMIService.ExecQuery("SELECT BytesReceivedPersec,BytesSentPersec FROM Win32_PerfRawData_Tcpip_NetworkInterface", "WQL", $wbemFlagReturnImmediately + $wbemFlagForwardOnly)
    
	If IsObj($colItems) then
		For $objItem In $colItems
			$newin = $objItem.BytesReceivedPersec
			$newout = $objItem.BytesSentPersec
			ExitLoop
		Next
	EndIf
	Return $Newout + $newin
EndFunc
 
Thanks DJNgoma,

I can't register on that forum. Register button keep on sending me to the read only portion of the site, though that little block thing is green, so I'm suppose to be able to use the proper site.

However I did some more digging and found a solution to my problem. It is probably not the best or correct way to code this, but it is now working for me. I just added a ExitLoop into the GetBW function.

You are welcome, and quite an interesting script to use. Could help with MWeb's shaping periods.
 
Top
Sign up to the MyBroadband newsletter
X