Sign in to follow this  
Followers 0
Ghastly_MIB

Ping

10 posts in this topic

I have made a simple script that checks the network for active computers with the ping command.

When is is scanning and the GUI is active is works without any problem. But when it's scanning and i select a other window, it fails each time.

I think the problem is the functions. When the GUI is not selected, the functions won't pass any command trouth.

Example

test("hallo")

Func test($i_test)
    MsgBox(0, "titel", $i_test)
EndFunc

Now the msgbox is empty when the GUI is not selected.

thanks,

Ghastly_MIB

Share this post


Link to post
Share on other sites



I have made a simple script that checks the network for active computers with the ping command.

When is is scanning and the GUI is active is works without any problem. But when it's scanning and i select a other window, it fails each time.

I think the problem is the functions. When the GUI is not selected, the functions won't pass any command trouth.

Example

test("hallo")

Func test($i_test)
    MsgBox(0, "titel", $i_test)
EndFunc

Now the msgbox is empty when the GUI is not selected.

thanks,

Ghastly_MIB

can you send some other example because that one works

Share this post


Link to post
Share on other sites

Here's my script.

It runs some ping tests, and it fails if you select a other window as the GUI

PC_Status.zip

Share this post


Link to post
Share on other sites

The problem is here:

While 1
        $line = StdoutRead($run)
        If @error = -1 Then ExitLoop
        $tot_line = $tot_line & $line
    Wend

It seems like when you focus to another GUI, StdoutRead cannot properly read $run's PID and returns @error = -1; that's why it fails while pinging. I don't know if this is a bug (since I am not familiar with Stdout functions) but theoritically it should work with this syntax.

However why don't you use the internal Ping() function to avoid such problems? I see that you have commented it out in your code.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

On the ping command, it will give the same problem... And set @error to 4

Edited by Ghastly_MIB

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

On the ping command, it will give the same problem... And set @error to 4

Really weird reaction of the ping function but nice dutch Gui anyway :P

I will check why it occurs

Hmm tested it does ping with a gui wich is minimized or so.

Only not your script

My test simple but not the weird error when minimized or not focussed

#include <GUIConstants.au3>
GUICreate ( "title" )
$wipkip = GUICtrlCreateLabel ( "leeg", 2,2,300,100)
$wipkip2 = GUICtrlCreateLabel ( "", 2,20,200,100)

Guisetstate()
$teller = 0
$msg = GUIGetMsg()
while NOT ($msg = $GUI_EVENT_CLOSE)
    $msg = GUIGetMsg()
    if $teller  <= 0 then 
        GUICtrlSetData ( $wipkip,ping("www.google.nl",500) & " ms naar www.google.nl")
        $teller = 50
    endif
    $teller -= 1        
    GUICtrlSetData ( $wipkip2,"Nog " & Stringformat ("%2.1f",$teller /10) & " seconden te gaan")
    sleep(100)
wend

It seems ping aint the problem

one small note you have the main loop with only 100ms wich will suck up some cpu time which you donot use because of the eventmode

better would be te remove the adlib enable and just change the sleep in the while loop to the delay var

While 1
    Sleep($controlle_sec * 1000)
    RefreshAll()
WEnd

it sucks up less cpu then (yes 1 % looks like nothing but is a lot for such a simple program)

but still looking why your script stops ping replys when minimized or not focussed

I tried bit change to the code it seems even the ping works here

see the ping reply from google next to the vernieuwen button

it still reping if you minimize or blur (unfocus)

But the list items seem to reset or something if not focussed

#Include <GUIConstants.au3>
#include <Constants.au3>
#include <GuiListView.au3>
#NoTrayIcon
Opt("GUIOnEventMode", 1)

Global $item_nr=0
Global $titel = "PC Status"
Global $lines_in_list = 17
Global $controlle_sec = 2

$gui = GUICreate($titel, 400, 400)
$list = GUICtrlCreateListView("Computernaam / IP|Omschrijving", 5, 5, 390, 340, $LVS_SHOWSELALWAYS+$LVS_SINGLESEL+$LVS_NOSORTHEADER+$LVS_SORTASCENDING, $LVS_EX_GRIDLINES+$LVS_EX_FLATSB)
_GUICtrlListViewSetColumnWidth($list, 0, 180)
_GUICtrlListViewSetColumnWidth($list, 1, 180)
$refresh = GUICtrlCreateButton("Vernieuwen", 10, 350, 75, 25)
$temp33 = GUICtrlCreateLabel("", 100, 350, 200, 25)
GUICtrlSetOnEvent($refresh, "RefreshAll")
GUICtrlSetState($refresh, $GUI_DISABLE)

$status = GUICtrlCreateLabel("", 5, 380, 300, 17, $SS_SUNKEN)
$percent = GUICtrlCreateLabel("0%", 310, 380, 80, 17, $SS_SUNKEN+$SS_RIGHT)

GUISetOnEvent($GUI_EVENT_CLOSE, "sluiten")
GUISetState()

Status("Bezig met laden van de lijst")
For $n = 1 To 500
    $ini = INIRead("PC status.ini", "LIST", $n, "")
    If $ini = "" Then ExitLoop
    $ini1 = StringSplit($ini, "|")
    If NOT _CheckIP($ini1[1]) Then
        If StringMid($ini, 1, 2) <> "\\" Then $ini = "\\" & $ini
    EndIf
    AddList($ini)
Next

RefreshAll()

While 1
    Sleep($controlle_sec * 1000)
    RefreshAll()
    guictrlsetdata($temp33,_ping("www.google.nl"))
WEnd

Func sluiten()
    Exit
EndFunc

Func RefreshAll()
    GUICtrlSetState($refresh, $GUI_DISABLE)
    Status("Bezig met controleren van pc's")
;AdlibDisable()
    Local $nr
    $nr = _GUICtrlListViewGetItemCount($list)*16
    _GUICtrlListViewScroll($list, 0, Number(-$nr))
    For $n = 0 To _GUICtrlListViewGetItemCount($list)-1
        If $n >= $lines_in_list Then
            _GUICtrlListViewScroll($list, 0, 16)
        EndIf
        $item = _GUICtrlListViewGetItemText($list, $n)
        $item = StringSplit($item, "|")
        Check($item[1], $n)
        GUICtrlSetData($percent, Round((100/_GUICtrlListViewGetItemCount($list)) * ($n+1),0)&"%")
    Next
    GUICtrlSetData($percent, "100%")
;AdlibEnable("RefreshAll", Number($controlle_sec&"000"))
    Status("Gereed")
    GUICtrlSetState($refresh, $GUI_ENABLE)
EndFunc

Func AddList($i_item)
    $item = GUICtrlCreateListViewItem($i_item, $list)
    Assign("item"&$item_nr, $item, 2)
    $item_nr += 1
    GUICtrlSetImage($item, "4.ico")
EndFunc

Func Check($i_ping, $i_nr)
    GUICtrlSetImage(Eval("item"&$i_nr), "3.ico")
    If _Ping($i_ping) > 0 Then
        GUICtrlSetImage(Eval("item"&$i_nr), "1.ico")
    Else
        GUICtrlSetImage(Eval("item"&$i_nr), "2.ico")
    EndIf
EndFunc

Func _Ping($i_ip)
    Local $tot_line
    If StringMid($i_ip, 1, 2) = "\\" Then
        $i_ip = StringTrimLeft($i_ip, 2)
    EndIf
;   $run = Run("ping -n 1 -l 1 "&$i_ip, @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
    Return Ping($i_ip, 250)
;   While 1
;       $line = StdoutRead($run)
;       If @error = -1 Then ExitLoop
;       $tot_line = $tot_line & $line
;   Wend
;   If StringInStr($tot_line, "=") Then
;       Return 1
;   Else
;       Return 0
;   EndIf
EndFunc

Func status($msg)
    GUICtrlSetData($status, $msg)
EndFunc

Func _CheckIP($ip)
    $temp = StringSplit($ip, ".")
    If $temp[0] <> 4 Then Return 0
    If $temp[1] > 255 OR NOT StringIsDigit($temp[1]) Then Return 0
    If $temp[2] > 255 OR NOT StringIsDigit($temp[2]) Then Return 0
    If $temp[3] > 255 OR NOT StringIsDigit($temp[3]) Then Return 0
    If $temp[4] > 255 OR NOT StringIsDigit($temp[4]) Then Return 0
    Return 1
EndFunc
Edited by MrSpacely

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

I think the problem is calling in a function a other function.

I realy don't know.

Edited by Ghastly_MIB

Share this post


Link to post
Share on other sites

If you replace (Line 58)

$item = _GUICtrlListViewGetItemText($list, $n)

with

$item = _GUICtrlListViewGetItemText($list, $n, -1, $titel)

it works.

The connection with the program is lost without the title, see the function in the UDF.

Groeten, Dick

Share this post


Link to post
Share on other sites

Thanks :P it works now

Bedankt hè!

Share this post


Link to post
Share on other sites

Great sollution, I was wondering what the problem was.

In the bus to work was thinking of a problem with the list.

But someone found out what

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0