Pookie62
(Fresh Scripter)
2006-01-11 10:36 AM
Loop ping ?

Hi,
I've a Kixform with a checkbox.
I'm pinging the computer to see if it's powered on or not.
The value of the checkbox is on or off.
But it's only checking once when the Kixform is opened.
How can I refresh the form so that it pings again ?
Here a piece of the code:

DIM $Computer
$Computer = 'NL-KDKF7PM'
If Ping($Computer)
$CheckBox1.Checked = "True"
Else
$CheckBox1.Checked = "False"
EndIf

Function Ping($PC)
DIM $PC
Shell'%comspec% /c ping -n 1 '+$PC+' >nul'
$Ping = NOT @ERROR
EndFunction

$Form.Show
While $Form.Visible
$=Execute($Form.DoEvents())
Loop
Exit 1


Thanks


JochenAdministrator
(KiX Supporter)
2006-01-11 10:58 AM
Re: Loop ping ?

Atach this ping function to a timer ...

Oh and the proper code for the ping stuff is (just test this and yours against a switched off computer) :


Code:

shell '%Comspec% /C ping -n 1 ' + $PC + ' | find /C "TTL=" > nul'
$Ping = not @error



LonkeroAdministrator
(KiX Master Guru)
2006-01-11 10:58 AM
Re: Loop ping ?

Code:

$Timer = $Form.Timer(1000)
$Timer.onTimer = 'If Ping($Computer)
$CheckBox1.Checked = "True"
Else
$CheckBox1.Checked = "False"
EndIf
'



for this code to work, you need to have novarsinstrings on.

[edit]
fixed the ontimer.


LonkeroAdministrator
(KiX Master Guru)
2006-01-11 11:05 AM
Re: Loop ping ?

"fixed" the timer from onTick to onTimer.
check your kixforms.chm for the correct timer tick event for your build.


Pookie62
(Fresh Scripter)
2006-01-11 11:31 AM
Re: Loop ping ?

Thanks guys !
Got it working


Pookie62
(Fresh Scripter)
2006-01-11 12:02 PM
Re: Loop ping ?

Ehhh....
Now I have another question..
I want to check several PC's and created a checkbox for every PC.
But only one is checked while I'm sure (Dosbox ping)that both PC are powered on..What am I doing wrong ?
Code:

$CheckPCk1 = $Form.Controls.CheckBox()
$CheckPCk1.BackColor = 212,208,200
$CheckPCk1.CheckAlign = 16
$CheckPCk1.CheckState = 0
$CheckPCk1.FontSize = 8,25
$CheckPCk1.Height = 21
$CheckPCk1.Left = 105
$CheckPCk1.Text = "testpc"
$CheckPCk1.Top = 105
$CheckPCk1.Width = 50

$CheckPCk2 = $Form.Controls.CheckBox()
$CheckPCk2.BackColor = 212,208,200
$CheckPCk2.CheckAlign = 16
$CheckPCk2.CheckState = 0
$CheckPCk2.FontSize = 8,25
$CheckPCk2.Height = 21
$CheckPCk2.Left = 105
$CheckPCk2.Text = ""
$CheckPCk2.Top = 150
$CheckPCk2.Width = 20


;KD END

$Op=SetOption('NoVarsInStrings','On')

DIM $Computer
$Computer = 'NL-KDKF7PM'
$Timer = $Form.Timer(500)
$Timer.onTimer = 'If Ping($Computer)
$CheckPCk1.Checked = "True"
Else
$CheckPCk1.Checked = "False"
EndIf
'

$Computer = 'NL-TKDBYB1L'
$Timer = $Form.Timer(500)
$Timer.onTimer = 'If Ping($Computer)
$CheckPCk2.Checked = "True"
Else
$CheckPCk2.Checked = "False"
EndIf
'

Function Ping($PC)
DIM $PC
shell '%Comspec% /C ping -n 1 ' + $PC + ' | find /C "TTL=" > nul'
$Ping = NOT @ERROR
EndFunction

$Form.Show
While $Form.Visible
$=Execute($Form.DoEvents())
Loop
Exit 1


Radimus
(KiX Supporter)
2006-01-11 12:09 PM
Re: Loop ping ?

you will need seperate timers for each computer

or

make one timer that calls a function, and that function runs through an array or listview of computer names and calls the ping function


Pookie62
(Fresh Scripter)
2006-01-11 12:16 PM
Re: Loop ping ?

Yeah was afraid array's would come up.. ;-)
Don't know how to write them.
Do you have an example for this ?
Thanks !


Radimus
(KiX Supporter)
2006-01-11 12:36 PM
Re: Loop ping ?

I was going to build this a while ago, I just never got around to it... I suppose I'll just start now.

Pookie62
(Fresh Scripter)
2006-01-11 12:42 PM
Re: Loop ping ?

I'm holding my breath... !

LonkeroAdministrator
(KiX Master Guru)
2006-01-11 12:51 PM
Re: Loop ping ?

you can do it with one timer just fine.
Code:

DIM $Computers
$Computers = 'NL-KDKF7PM','NL-TKDBYB1L'
$Timer = $Form.Timer(5000)
For $count=0 to ubound($Computers)
$Timer.onTimer = $Timer.onTimer +
'If Ping(' + $Computers[$count] + ')
$CheckPCk' + ($count+1) + '.Checked = "True"
Else
$CheckPCk' + ($count+1) + '.Checked = "False"
EndIf'
Next



having the timer loop twice every second is way too quick, so I reduced it back to 5s.


Pookie62
(Fresh Scripter)
2006-01-11 01:04 PM
Re: Loop ping ?

Oke, let me post the entire code. I'm getting an error in expression on line 1..
Code:

Break On
$System = CreateObject("Kixtart.System")


;KD START

$Form = $System.Form()
$Form.BackColor = 212,208,200
$Form.FontSize = 8,25
$Form.Height = 585
$Form.Left = 90
$Form.Text = "Kandidaten PC's"
$Form.Top = 12
$Form.Width = 354
$Test = $Form.Controls.Button()
$Test.FlatStyle = 3
$Test.FontSize = 8,25
$Test.Height = 24
$Test.Left = 0
$Test.Text = " Kamer 1 (203)"
$Test.Top = 105
$Test.Width = 95
$Test.OnClick = 'SHELL "\\nlmoon\apps\KandPC\NL-KDKF7PK-Kamer1.bat"'
$Label1 = $Form.Controls.Label()
$Label1.BackColor = 212,208,200
$Label1.FontBold = "True"
$Label1.FontSize = 12,25
$Label1.Height = 36
$Label1.Left = 30
$Label1.Text = "Klik op knop om PC op te starten"
$Label1.Top = 15
$Label1.Width = 280
$Button2 = $Form.Controls.Button()
$Button2.FlatStyle = 3
$Button2.FontSize = 8,25
$Button2.Height = 24
$Button2.Left = 0
$Button2.Text = "Kamer 2 (204)"
$Button2.Top = 150
$Button2.Width = 94
$Button2.OnClick = 'SHELL "\\nlmoon\apps\KandPC\NL-TKDBYB1L-Kamer2.bat"'
$Button3 = $Form.Controls.Button()
$Button3.FontSize = 8,25
$Button3.Height = 23
$Button3.Left = 165
$Button3.Text = "TestPC-Aan"
$Button3.Top = 150
$Button3.Width = 75
$Button3.OnClick = 'SHELL "\\nlmoon\apps\KandPC\NL-KDKF7PM.bat"'
$Button4 = $Form.Controls.Button()
$Button4.FlatStyle = 3
$Button4.FontSize = 8,25
$Button4.Height = 24
$Button4.Left = 0
$Button4.Text = "Kamer 3 (205)"
$Button4.Top = 195
$Button4.Width = 95
$Button4.OnClick = 'SHELL "\\nlmoon\apps\KandPC\NL-TKDBYA7P-Kamer3.bat"'
$Button5 = $Form.Controls.Button()
$Button5.FlatStyle = 3
$Button5.FontSize = 8,25
$Button5.Height = 24
$Button5.Left = 0
$Button5.Text = "Kamer 4 (206)"
$Button5.Top = 240
$Button5.Width = 95
$Button5.OnClick = 'SHELL "\\nlmoon\apps\KandPC\NL-TKDBYA8W-Kamer4.bat"'
$Button6 = $Form.Controls.Button()
$Button6.FlatStyle = 3
$Button6.FontSize = 8,25
$Button6.Height = 24
$Button6.Left = 0
$Button6.Text = "Kamer 5 (207)"
$Button6.Top = 285
$Button6.Width = 95
$Button6.OnClick = 'SHELL "\\nlmoon\apps\KandPC\NL-KDKK0HY-Kamer5.bat"'
$Button7 = $Form.Controls.Button()
$Button7.FontSize = 8,25
$Button7.Height = 23
$Button7.Left = 0
$Button7.Text = "Kamer 6 (208)"
$Button7.Top = 330
$Button7.Width = 95
$Button7.OnClick = 'SHELL "\\nlmoon\apps\KandPC\NL-TKDBYB1K-Kamer6.bat"'
$Button8 = $Form.Controls.Button()
$Button8.FlatStyle = 3
$Button8.FontSize = 8,25
$Button8.Height = 24
$Button8.Left = 0
$Button8.Text = "Kamer 7 (209)"
$Button8.Top = 375
$Button8.Width = 95
$Button8.OnClick = 'SHELL "\\nlmoon\apps\KandPC\NL-TKDBYA7W-Kamer7.bat"'
$Button9 = $Form.Controls.Button()
$Button9.FlatStyle = 3
$Button9.FontSize = 8,25
$Button9.Height = 23
$Button9.Left = 0
$Button9.Text = "Kamer 8 (210)"
$Button9.Top = 420
$Button9.Width = 95
$Button9.OnClick = 'SHELL "\\nlmoon\apps\KandPC\NL-TKDBYB1X-Kamer8.bat"'
$Button10 = $Form.Controls.Button()
$Button10.FlatStyle = 3
$Button10.FontSize = 8,25
$Button10.Height = 24
$Button10.Left = 0
$Button10.Text = "Kamer 9 (211)"
$Button10.Top = 465
$Button10.Width = 95
$Button10.OnClick = 'SHELL "\\nlmoon\apps\KandPC\NL-KGX150-Kamer9.bat"'
$Button12 = $Form.Controls.Button()
$Button12.FontSize = 8,25
$Button12.Height = 24
$Button12.Left = 165
$Button12.Text = "TestPC-overname"
$Button12.Top = 195
$Button12.Width = 111
$Button12.OnClick = 'SHELL "C:\Program Files\RealVNC\vncviewer.exe NL-KDKF7PM"'

$CheckPCk1 = $Form.Controls.CheckBox()
$CheckPCk1.BackColor = 212,208,200
$CheckPCk1.CheckAlign = 16
$CheckPCk1.CheckState = 0
$CheckPCk1.FontSize = 8,25
$CheckPCk1.Height = 21
$CheckPCk1.Left = 105
$CheckPCk1.Text = "testpc"
$CheckPCk1.Top = 105
$CheckPCk1.Width = 50

$CheckPCk2 = $Form.Controls.CheckBox()
$CheckPCk2.BackColor = 212,208,200
$CheckPCk2.CheckAlign = 16
$CheckPCk2.CheckState = 0
$CheckPCk2.FontSize = 8,25
$CheckPCk2.Height = 21
$CheckPCk2.Left = 105
$CheckPCk2.Text = ""
$CheckPCk2.Top = 150
$CheckPCk2.Width = 20


;KD END

$Op=SetOption('NoVarsInStrings','On')

DIM $Computers
$Computers = 'NL-KDKF7PM','NL-TKDBYB1L'
$Timer = $Form.Timer(5000)
For $count=0 to ubound($Computers)
$Timer.onTimer = $Timer.onTimer +
'If Ping(' + $Computers[$count] + ')
$CheckPCk' + ($count+1) + '.Checked = "True"
Else
$CheckPCk' + ($count+1) + '.Checked = "False"
EndIf'
Next

Function Ping($PC)
DIM $PC
shell '%Comspec% /C ping -n 1 ' + $PC + ' | find /C "TTL=" > nul'
$Ping = NOT @ERROR
EndFunction

$Form.Show
While $Form.Visible
$=Execute($Form.DoEvents())
Loop
Exit 1


LonkeroAdministrator
(KiX Master Guru)
2006-01-11 01:22 PM
Re: Loop ping ?

sorry, my bad.
need to change:
'If Ping(' + $Computers[$count] + ')

to:
' If Ping("' + $Computers[$count] + '")

the space before the if is needed...


LonkeroAdministrator
(KiX Master Guru)
2006-01-11 01:29 PM
Re: Loop ping ?

k, your code is kinda not optimized...
you could consider using listview.

or, just doing the button creation into array would ease the coding a lot.


Pookie62
(Fresh Scripter)
2006-01-11 02:06 PM
Re: Loop ping ?

Quote:

k, your code is kinda not optimized...
you could consider using listview.

or, just doing the button creation into array would ease the coding a lot.



I know it's not optimized, but I'm not expierenced enough to write it myself. although I read a lot on these Forums.
I've even never heard of listview...
Thanks for your time..
I'll dive into the forrest of search again and see what I can find
By the way, still getting an error in expression on line 20 now
Checkboxes are working ok though !


LonkeroAdministrator
(KiX Master Guru)
2006-01-11 02:29 PM
Re: Loop ping ?

hey, got a bit bored and wrote this for you to try:
Code:

Break On
$Op=SetOption('NoVarsInStrings','On')
$System = CreateObject("Kixtart.System")


;KD START

$Form = $System.Form()
$Form.BackColor = 212,208,200
$Form.FontSize = 8,25
$Form.Height = 585
$Form.Left = 90
$Form.Text = "Kandidaten PC's"
$Form.Top = 12
$Form.Width = 354

global $_pingers
MakeKamer('NL-KDKF7PM',"Kamer 1 (203)",'SHELL "\\nlmoon\apps\KandPC\NL-KDKF7PK-Kamer1.bat"')
MakeKamer('NL-TKDBYB1L',"Kamer 2 (204)",'SHELL "\\nlmoon\apps\KandPC\NL-TKDBYB1L-Kamer2.bat"')
MakeKamer('some',"Kamer 3 (205)",'SHELL "\\nlmoon\apps\KandPC\NL-TKDBYA7P-Kamer3.bat"')
MakeKamer('someother',"Kamer 4 (206)",'SHELL "\\nlmoon\apps\KandPC\NL-TKDBYA8W-Kamer4.bat"')
MakeKamer('yep',"Kamer 5 (207)",'SHELL "\\nlmoon\apps\KandPC\NL-KDKK0HY-Kamer5.bat"')
MakeKamer('basta',"Kamer 6 (208)",'SHELL "\\nlmoon\apps\KandPC\NL-TKDBYB1K-Kamer6.bat"')
MakeKamer('blaah',"Kamer 7 (209)",'SHELL "\\nlmoon\apps\KandPC\NL-TKDBYA7W-Kamer7.bat"')
MakeKamer('weirdWKSTAnames',"Kamer 8 (210)",'SHELL "\\nlmoon\apps\KandPC\NL-TKDBYB1X-Kamer8.bat"')
MakeKamer('aintThey',"Kamer 9 (211)",'SHELL "\\nlmoon\apps\KandPC\NL-KGX150-Kamer9.bat"')


$Label1 = $Form.Controls.Label()
$Label1.BackColor = 212,208,200
$Label1.FontBold = "True"
$Label1.FontSize = 12,25
$Label1.Height = 36
$Label1.Left = 30
$Label1.Text = "Klik op knop om PC op te starten"
$Label1.Top = 15
$Label1.Width = 280

$Button3 = $Form.Controls.Button()
$Button3.FontSize = 8,25
$Button3.Height = 23
$Button3.Left = 210
$Button3.Text = "TestPC-Aan"
$Button3.Top = 150
$Button3.Width = 75
$Button3.OnClick = 'SHELL "\\nlmoon\apps\KandPC\NL-KDKF7PM.bat"'
$Button12 = $Form.Controls.Button()
$Button12.FontSize = 8,25
$Button12.Height = 24
$Button12.Left = 210
$Button12.Text = "TestPC-overname"
$Button12.Top = 195
$Button12.Width = 111
$Button12.OnClick = 'SHELL "C:\Program Files\RealVNC\vncviewer.exe NL-KDKF7PM"'

$Timer = $Form.Timer(5000)
$Timer.onTimer = 'PingEmAll()'

$Form.Show
While $Form.Visible
$ev = $Form.DoEvents()
$ev ?
$=Execute($ev)
Loop
Exit 1

Function MakeKamer($pcName, $inputName,$inputClick)
dim $button,$checkBox
if isDeclared($_GamerButton_TOP) ;is this the first time this udf is called?
$_GamerButton_TOP = $_GamerButton_TOP + 45
else
;it is, lets make the var and define the start location for the button.
Global $_GamerButton_TOP
$_GamerButton_TOP = 105
endif

$button = $Form.Controls.Button()
$button.FlatStyle = 3
$button.FontSize = 8
$button.Height = 24
$button.Left = 0
$button.Text = $inputName
$button.Top = $_GamerButton_TOP
$button.Width = 95
$button.OnClick = $inputClick

$CheckBox = $Form.Controls.CheckBox()
$CheckBox.BackColor = 212,208,200
$CheckBox.CheckAlign = 16
$CheckBox.CheckState = 0
$CheckBox.FontSize = 8
$CheckBox.Height = 21
$CheckBox.Left = 105
$CheckBox.Text = $pcName
$CheckBox.Top = $_GamerButton_TOP
$CheckBox.Width = 100
$CheckBox.tag = $pcName ;pinger uses this tag.

redim $_pingers[ubound($_pingers)+1]
$_pingers[ubound($_pingers)] = $CheckBox
endfunction

Function PingEmAll()
dim $system
For each $system in $_pingers
If Ping($system.tag)
$system.Checked = "True"
Else
$system.Checked = "False"
EndIf
Next
EndFunction

Function Ping($PC)
DIM $PC
shell '%Comspec% /C ping -n 1 ' + $PC + ' | find /C "TTL=" > nul'
$Ping = NOT @ERROR
EndFunction



Gargoyle
(MM club member)
2006-01-11 02:43 PM
Re: Loop ping ?

To see how I handled the same type of thing here is a script I wrote several years ago.

http://www.kixforms.org/forum/viewtopic.php?t=810


Pookie62
(Fresh Scripter)
2006-01-11 02:50 PM
Re: Loop ping ?

Wow! Thanks Jooel !!
Only thing.. The form opens and after the first 5 secs a dosbox is opened echoing: PingEmAll()
Then looping in that..

BTW. no such weird WKSTA names.. (lol) just the SerialNr with our country (NL before it..)


LonkeroAdministrator
(KiX Master Guru)
2006-01-11 03:59 PM
Re: Loop ping ?

yes, the output comes from:
Code:

$Form.Show
While $Form.Visible
$ev = $Form.DoEvents()
$ev ?
$=Execute($ev)
Loop
Exit 1


just comment out $ev ? and you will no longer get the dosbox.


Radimus
(KiX Supporter)
2006-01-11 07:29 PM
Re: Loop ping ?

I was working on this this morning, but had to stop to take my windstar to the transmission shop...

Would it be best to filter out the non-pingables?

This can go in one of 2 directions:
1 a subnet monitor to show what is online
2 a uptime monitor to inform if something goes down.

You really wouldn't want to be constantly pinging EVERYTHING on a subnet, so ping everything on demand or ping a few things repeatedly...

You can see what I was looking to do. If you do not enter an IP, it takes your current IP and assumes Class C subnet. Otherwise input CIDR of the target network

Code:

Break On
$System = CreateObject("Kixtart.System")


;************* Form **************
$Form = $System.Form()
$Form.Height = 350
$Form.Left = 37
$Form.Text = "Subnet Pinger"
$Form.Top = 22
$Form.Width = 250
;**************************************

$PanelTop = $Form.Panel()
$PanelTop.BorderStyle = 1
$PanelTop.Dock = 1
$PanelTop.Height = 35
$nul = $Form.Controls.Add($PanelTop)

$PanelBottom = $Form.Panel()
$PanelBottom.BorderStyle = 1
$PanelBottom.Dock = 2
$PanelBottom.Height = 25
$nul = $Form.Controls.Add($PanelBottom)

$PanelCenter = $Form.Panel()
$PanelCenter.BorderStyle = 1
$PanelCenter.Dock = 5
$nul = $Form.Controls.Add($PanelCenter)

$TextBox3 = $Form.TextBox('',5,5,145,20)

$Button4 = $Form.Button('Load Subnet',160,5,75,20)
$button4.OnClick = "LoadSubnet"

$ListView5 = $PanelCenter.ListView()
$ListView5.Dock = 5
$ListView5.GridLines = "True"
$ListView5.AllowColumnReorder = "True"
$ListView5.FullRowSelect = "True"

$nul = $PanelCenter.Controls.Add($ListView5)
$nul = $ListView5.Columns.Add("IPAddress",100)
$nul = $ListView5.Columns.Add("Status",119)

$nul = $PanelTop.Controls.Add($TextBox3)
$nul = $PanelTop.Controls.Add($Button4)



$Form.Show
While $Form.Visible
$=Execute($Form.DoEvents())
Loop
Exit 1

Function LoadSubnet
if not instr($TextBox3.Text,'.')
$TextBox3.Text =join(split(@IPADDRESS0),'')
endif
$ListView5.Items.Clear
if not instr($TextBox3.Text,"/")
$TextBox3.Text = $TextBox3.Text +'/24'
endif
$arrIPs = EnumIPRange($TextBox3.Text)
for each $ip in $arrIPs
if Ping($ip)
$item = $ListView5.Items.Add($IP)
endif
next

EndFunction

Function Ping($PC)
DIM $PC
shell '%Comspec% /C ping -n 1 ' + $PC + ' | find /C "TTL=" > nul'
$Ping = NOT @ERROR
EndFunction

Function EnumIPRange($sIPaddress,optional $sNetMask)
Dim $aiStartRange,$aiMaskBits,$aiEndRange[4],$iHostCount,$i
Dim $cidr,$fac,$mask,$temp,$temp2,$a,$b
Dim $iOctet1,$iOctet2,$iOctet3,$iOctet4
Dim $tempArray[1],$arrOctect[4]

if instr($sIPaddress,'/')
$cidr=val(split($sIPaddress,'/')[1])
$sIPaddress=split($sIPaddress,'/')[0]
$sNetMask=''
for $a = 1 to $cidr
$mask=$mask+'1'
next
for $a = $cidr + 1 to 32
$mask=$mask+'0'
next
for $a = 0 to 3
$temp=substr($mask,$a*8+1,8)
$temp2=0
$fac=256
for $b=1 to 8
$fac = $fac / 2
$temp2 = $temp2 + val(substr($temp,$b,1)) * $fac
next
if not $a=3
$sNetMask=$sNetMask+$temp2+ '.'
else
$sNetMask=$sNetMask+$temp2
endif
next
endif

$iHostCount=1

$aiStartRange=Split($sIPaddress,".")
$aiMaskBits=Split($sNetMask,".")
Redim Preserve $aiStartRange[4]
Redim Preserve $aiMaskBits[4]

For $i = 0 To 3
$aiMaskBits[$i] =Val($aiMaskBits[$i]) & 255
$aiStartRange[$i] =Val($aiStartRange[$i]) & $aiMaskBits[$i]
$aiEndRange[$i] =$aiStartRange[$i]+(255-$aiMaskBits[$i])
$iHostCount =$iHostCount*($aiEndRange[$i]-$aiStartRange[$i]+1)
Next

redim $temparray[$iHostCount]
$i=0
For $iOctet1 = $aiStartRange[0] To $aiEndRange[0]
For $iOctet2 = $aiStartRange[1] To $aiEndRange[1]
For $iOctet3 = $aiStartRange[2] To $aiEndRange[2]
For $iOctet4 = $aiStartRange[3] To $aiEndRange[3]
$temparray[$i]=''+$iOctet1+'.'+$iOctet2+'.'+$iOctet3+'.'+$iOctet4
$i=$i+1
Next
Next
Next
Next
$EnumIPRange=$temparray
EndFunction




Pookie62
(Fresh Scripter)
2006-01-12 08:22 AM
Re: Loop ping ?

Jooel, still got a minor issue..
Checkboxes aren't checked when machine is on..
Any idea why not ?

Radimus: thanks for your script too !
Really appreciate the support and time you spend, both of you !!


LonkeroAdministrator
(KiX Master Guru)
2006-01-12 03:55 PM
Re: Loop ping ?

not checked?
the issue is around here:
Code:

If Ping($system.tag)
$system.Checked = "True"
Else
$system.Checked = "False"
EndIf



so, lets make debug code:
Code:

"Pinging: " $system.tag ?
If Ping($system.tag)
"Response" ?
$system.Checked = "True"
Else
"system is offline" ?
$system.Checked = "False"
EndIf



if the correct text is coming out, the issue is of kixforms nature.
if wrong response, there is something wrong either with the tagged name or the ping() udf.


Pookie62
(Fresh Scripter)
2006-01-12 09:53 PM
Re: Loop ping ?

Hi Jooel,
Something in the loop or Foreach must be wrong..
It's only pinging ( and looping the ping) the last defined MakeKamer(...etc


LonkeroAdministrator
(KiX Master Guru)
2006-01-12 10:28 PM
Re: Loop ping ?

hmm...
change the:
global $_pingers

to:
global $_pingers[]


Pookie62
(Fresh Scripter)
2006-01-12 10:31 PM
Re: Loop ping ?

Sorry no difference.. I defined same comp twice for testing > only the last one is checked

LonkeroAdministrator
(KiX Master Guru)
2006-01-12 10:37 PM
Re: Loop ping ?

ja.
I went testing and found out the same.

me silly didn't test this before.
my redim line lacked the preserve keyword

redim preserve $_pingers[ubound($_pingers)+1]


Pookie62
(Fresh Scripter)
2006-01-12 10:46 PM
Re: Loop ping ?

:-)
Still many many thanks !!! Working perfectly now !
Last question(promise..lol)
I created a button to quit the form, but when I hit before the pings start, it quitting rightaway, when the pinging has started, it takes half a minute before the forms closes.. Any specific reason why ?
code:
$ButtQuit = $Form.Controls.Button()
$ButtQuit.Anchor = 10
$ButtQuit.Default = "True"
$ButtQuit.FontSize = 8,25
$ButtQuit.Height = 23
$ButtQuit.Left = 210
$ButtQuit.Text = "Nokken"
$ButtQuit.Top = 240
$ButtQuit.Width = 75
$ButtQuit.OnClick = "quit"


LonkeroAdministrator
(KiX Master Guru)
2006-01-13 05:59 AM
Re: Loop ping ?

sure, you are pinging something like 10 machines.
if they all fail the ping, it takes some time...
oh...
and some new pings are already added to the queye.
add this line to the start of pingEmAll() UDF:
$Timer.onTimer = ''

and then to the end of it:
$Timer.onTimer = 'PingEmAll()'


Pookie62
(Fresh Scripter)
2006-01-13 09:11 AM
Re: Loop ping ?

Thanks again Jooel !

bofh71
(Fresh Scripter)
2006-01-15 02:57 PM
Re: Loop ping ?

Pookie62
is there any chance that you will post the entire script with all the corrections made ??

Thanks
Jan V.


Pookie62
(Fresh Scripter)
2006-01-16 01:21 PM
Re: Loop ping ?

Sure Jan, no prob

Code:
Break On
$Op=SetOption('NoVarsInStrings','On')
$System = CreateObject("Kixtart.System")

;KD START

$Form = $System.Form()
$Form.BackColor = 128,255,255
$Form.FontSize = 8,25
$Form.Height = 585
$Form.Left = 90
$Form.Text = "Kandidaten PC's"
$Form.Top = 12
$Form.Width = 354

global $_pingers
MakeKamer('NL-KDKF7PK',"Kamer 1 (203)",'SHELL "\\Path-to-wol.exe (Wake on Lan"')
MakeKamer('NL-TKDBYB1L',"Kamer 2 (204)",'SHELL "\\Path-to-wol.exe (Wake on Lan"')
MakeKamer('NL-TKDBYA7P',"Kamer 3 (205)",'SHELL "\\Path-to-wol.exe (Wake on Lan"')
MakeKamer('NL-TKDBYA8W',"Kamer 4 (206)",'SHELL "\\Path-to-wol.exe (Wake on Lan"')
MakeKamer('NL-KDKK0HY',"Kamer 5 (207)",'SHELL "\\Path-to-wol.exe (Wake on Lan"')
MakeKamer('NL-TKDBYB1K',"Kamer 6 (208)",'SHELL "\\Path-to-wol.exe (Wake on Lan"')
MakeKamer('NL-TKDBYA7W',"Kamer 7 (209)",'SHELL "\\Path-to-wol.exe (Wake on Lan"')
MakeKamer('NL-TKDBYB1X',"Kamer 8 (210)",'SHELL "\\Path-to-wol.exe (Wake on Lan"')
MakeKamer('NL-KGX150',"Kamer 9 (211)",'SHELL "\\Path-to-wol.exe (Wake on Lan"')

global $_vncers
MakeVNC('NL-KDKF7PK',"Kamer 1 (203)",'SHELL "C:\Program Files\RealVNC\vncviewer.exe NL-KDKF7PK"')
MakeVNC('NL-TKDBYB1L',"Kamer 2 (204)",'SHELL "C:\Program Files\RealVNC\vncviewer.exe NL-TKDBYB1L"')
MakeVNC('NL-TKDBYA7P',"Kamer 3 (205)",'SHELL "C:\Program Files\RealVNC\vncviewer.exe NL-TKDBYA7P"')
MakeVNC('NL-TKDBYA8W',"Kamer 4 (206)",'SHELL "C:\Program Files\RealVNC\vncviewer.exe NL-TKDBYA8W"')
MakeVNC('NL-KDKK0HY',"Kamer 5 (207)",'SHELL "C:\Program Files\RealVNC\vncviewer.exe NL-KDKK0HY"')
MakeVNC('NL-TKDBYB1K',"Kamer 6 (208)",'SHELL "C:\Program Files\RealVNC\vncviewer.exe NL-TKDBYB1K"')
MakeVNC('NL-TKDBYA7W',"Kamer 7 (209)",'SHELL "C:\Program Files\RealVNC\vncviewer.exe NL-TKDBYA7W"')
MakeVNC('NL-TKDBYB1X',"Kamer 8 (210)",'SHELL "C:\Program Files\RealVNC\vncviewer.exe NL-TKDBYB1X"')
MakeVNC('NL-KGX150',"Kamer 9 (211)",'SHELL "C:\Program Files\RealVNC\vncviewer.exe NL-KGX150"')


$Label1 = $Form.Controls.Label()
$Label1.BackColor = 128,255,255
$Label1.FontBold = "True"
$Label1.FontSize = 12,25
$Label1.Height = 36
$Label1.Left = 30
$Label1.Text = "Klik op knop om PC op te starten"
$Label1.Top = 15
$Label1.Width = 280

$Label2 = $Form.Controls.Label()
$Label2.BackColor = 128,255,255
$Label2.FlatStyle = 3
$Label2.FontBold = "True"
$Label2.FontSize = 8,25
$Label2.FontUnderline = "True"
$Label2.ForeColor = 0,0,255
$Label2.Height = 24
$Label2.Left = 15
$Label2.Text = "Aanzetten"
$Label2.Top = 75
$Label2.Width = 100

$Label4 = $Form.Controls.Label()
$Label4.BackColor = 128,255,255
$Label4.FlatStyle = 3
$Label4.FontBold = "True"
$Label4.FontSize = 8,25
$Label4.FontUnderline = "True"
$Label4.ForeColor = 0,0,255
$Label4.Height = 24
$Label4.Left = 165
$Label4.Text = "Overnemen"
$Label4.Top = 75
$Label4.Width = 105

$Timer = $Form.Timer(5000)
;$Timer.onTimer = 'PingEmAll()' ;Created button for pinging once instead of all the time (every 5 secs)
$Button3 = $Form.Controls.Button()
$Button3.FontSize = 8,25
$Button3.Height = 21
$Button3.Left = 100
$Button3.Text = "on/off ?"
$Button3.Top = 50
$Button3.Width = 50
$Button3.OnClick = 'PingEmAll()'

$ButtQuit = $Form.Controls.Button()
$ButtQuit.Anchor = 5
$ButtQuit.FontSize = 8,25
$ButtQuit.FontBold = "True"
$ButtQuit.Height = 23
$ButtQuit.Left = 120
$ButtQuit.Text = "Nokken"
$ButtQuit.Top = 520
$ButtQuit.Width = 75
$ButtQuit.OnClick = "quit"

$Form.Show
While $Form.Visible
$ev = $Form.DoEvents()
;$ev ? ; Shows DosBox, commented out
$=Execute($ev)
Loop
Exit 1

Function MakeVNC($pcName, $inputName,$inputClick)
dim $button2
if isDeclared($_VNCButton_TOP) ;is this the first time this udf is called?
$_VNCButton_TOP = $_VNCButton_TOP + 45
else
;it is, lets make the var and define the start location for the button.
Global $_VNCButton_TOP
$_VNCButton_TOP = 105
endif

$button2 = $Form.Controls.Button()
$button2.FlatStyle = 3
$button2.FontSize = 8
$button2.Height = 24
$button2.Left = 165
$button2.Text = $inputName
$button2.Top = $_VNCButton_TOP
$button2.Width = 95
$button2.OnClick = $inputClick

redim preserve $_vncers[ubound($_vncers)+1]
endfunction

Function MakeKamer($pcName, $inputName,$inputClick)
dim $button,$checkBox
if isDeclared($_GamerButton_TOP) ;is this the first time this udf is called?
$_GamerButton_TOP = $_GamerButton_TOP + 45
else
;it is, lets make the var and define the start location for the button.
Global $_GamerButton_TOP
$_GamerButton_TOP = 105
endif

$button = $Form.Controls.Button()
$button.FlatStyle = 3
$button.FontSize = 8
$button.Height = 24
$button.Left = 15
$button.Text = $inputName
$button.Top = $_GamerButton_TOP
$button.Width = 95
$button.OnClick = $inputClick

$CheckBox = $Form.Controls.CheckBox()
$CheckBox.BackColor = 128,255,255
$CheckBox.CheckAlign = 16
$CheckBox.CheckState = 0
$CheckBox.FontSize = 8
$CheckBox.Height = 21
$CheckBox.Left = 120
;$CheckBox.Text = $pcName ; Commented out, no need to show $pcname again
$CheckBox.Top = $_GamerButton_TOP
$CheckBox.Width = 10
$CheckBox.tag = $pcName ;pinger uses this tag.

redim preserve $_pingers[ubound($_pingers)+1]
$_pingers[ubound($_pingers)] = $CheckBox
endfunction

Function PingEmAll()
dim $system
For each $system in $_pingers
If Ping($system.tag)
$system.Checked = "True"
Else
$system.Checked = "False"
EndIf
Next
EndFunction

Function Ping($PC)
DIM $PC
shell '%Comspec% /C ping -n 1 ' + $PC + ' | find /C "TTL=" > nul'
$Ping = NOT @ERROR
EndFunction