|
|
|||||||
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 |
||||||||
|
|
|||||||
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:
|
||||||||
|
|
|||||||
Code:
for this code to work, you need to have novarsinstrings on. [edit] fixed the ontimer. |
||||||||
|
|
|||||||
"fixed" the timer from onTick to onTimer. check your kixforms.chm for the correct timer tick event for your build. |
||||||||
|
|
|||||||
Thanks guys ! Got it working |
||||||||
|
|
|||||||
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 |
||||||||
|
|
|||||||
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 |
||||||||
|
|
|||||||
Yeah was afraid array's would come up.. ;-) Don't know how to write them. Do you have an example for this ? Thanks ! |
||||||||
|
|
|||||||
I was going to build this a while ago, I just never got around to it... I suppose I'll just start now. |
||||||||
|
|
|||||||
I'm holding my breath... ! |
||||||||
|
|
|||||||
you can do it with one timer just fine. Code:
having the timer loop twice every second is way too quick, so I reduced it back to 5s. |
||||||||
|
|
|||||||
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 |
||||||||
|
|
|||||||
sorry, my bad. need to change: 'If Ping(' + $Computers[$count] + ') to: ' If Ping("' + $Computers[$count] + '") the space before the if is needed... |
||||||||
|
|
|||||||
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. |
||||||||
|
|
|||||||
Quote: 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 ! |
||||||||
|
|
|||||||
hey, got a bit bored and wrote this for you to try: Code:
|
||||||||
|
|
|||||||
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 |
||||||||
|
|
|||||||
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..) |
||||||||
|
|
|||||||
yes, the output comes from: Code:
just comment out $ev ? and you will no longer get the dosbox. |
||||||||
|
|
|||||||
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:
|
||||||||
|
|
|||||||
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 !! |
||||||||
|
|
|||||||
not checked? the issue is around here: Code:
so, lets make debug code: Code:
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. |
||||||||
|
|
|||||||
Hi Jooel, Something in the loop or Foreach must be wrong.. It's only pinging ( and looping the ping) the last defined MakeKamer(...etc |
||||||||
|
|
|||||||
hmm... change the: global $_pingers to: global $_pingers[] |
||||||||
|
|
|||||||
Sorry no difference.. I defined same comp twice for testing > only the last one is checked |
||||||||
|
|
|||||||
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] |
||||||||
|
|
|||||||
:-) 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" |
||||||||
|
|
|||||||
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()' |
||||||||
|
|
|||||||
Thanks again Jooel ! |
||||||||
|
|
|||||||
Pookie62 is there any chance that you will post the entire script with all the corrections made ?? Thanks Jan V. |
||||||||
|
|
|||||||
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 |