Okay, but just note that since $scid(0) counts only opened serv er windows, any server windows you have open that aren\'t connected result in an error and halts the script. I know that since I used to use a similar method to what you have.
Therefore, I recommend you add some sort of checking to the script like if ($network != $null) { amsg } or something of that sort.