Don't know why we're all reinventing the wheel, especially for something that's effectively pointless in the current concept (see my comments below on Ping). Maybe 15 years as a technology instructor makes me look at things from a different perspective, but found myself shaking my head this morning.

First rule of any project - define the goal and then outline the process. Write the process down, not in code, so you can read it and see if it makes sense.

Goal: We want to obtain a list of computers in the network at a given point in time and identify their operational status - Up or Down.

Process - We need to:
  • Read a file to get a list of hostnames - ReadFile() would return them in an array, easy to enumerate with a "For Each" loop.
  • Ping a host once and determine if it responds. Well, this is pointless for the desired goal.. A computer may not reply if it is busy, the routers may drop ICMP packets if they are busy, so there's a fair chance you'll not get a reply with just one ping - FALSE NEGATIVE. Then, most newer PC hardware will reply to a ping once the network hardware has been initialized by loading an O/S, even if the O/S hangs. So, you get a reply from the NIC from an effectively dead computer - FASLE POSITIVE.

    If you must use Ping(), the functions that I use will ping a number of times to account for the low priority of ICMP, but will exit after the first succesful reply. The result is fast and accurate. I usually use that to determine if a computer can reply, and then make some other type of connection, such as reading the service list on a Windows computer (WMISvcMgr('list', ,,'HostName') or making some other type of socket connection to *nix systems to see if it's actually "alive". This requires more advanced capabilities than what Kix offers today, so I use a Socket Ping utility I wrote in Perl for the *nix systems. KixForms has socket support, but it's currently broken. The point is - you must actually COMMUNICATE to the host O/S to determine if it is "up" or "down" - something Ping can't really do.

    A combination of Ping() and WMISvcMgr() will provide accurate results with minimal delay.
  • Determine the result and write to an Excel file - the xlLib UDF library exists with all the capabilities to read/write/format Excel files with minimal effort or understanding of COM.
I'm not picking on Saleem - asking questions is how we all learn, but gee-whillikers, guys! This can be done in a few lines of new code, encouraging the use of proven, tested UDFs. If you're a new coder, you can treat the UDF as a "black box", just as any other built-in function, and get your code operational quickly. Then, you can go back and examine the UDFs and really get an education in coding by picking apart that logic - slowly and methodically. These are luxuries you may not have when under pressure to get a job done, but are critical to expanding your knowledge. The logic, and even the coding style found in UDFs gives you a broader knowledge base than any book can provide.

I also keep referencing my Kix library. Most of the functions have been posted here on KORG, but I keep my library up to date, and the latest versions from my production library are formatted and pushed to the web site nightly. These functions meet our internal coding standards, so even if the function was written by someone else, it will often have many more comments explaining the what and why of the logic.

Here's some basic code to put this together with the UDFs I've mentioned. It's PSEUDO-CODE, meaning it's the concept, untested, and makes assumptions that you'll locate and load the needed UDFs and add some good practices like variable declarations and error checking. All but the ReadFile() UDF are on the resource pages of my web site, updated directly from my active development library, so much searching is eliminated.

Glenn
 Code:
; make sure followint UDFs are either CALLed or pasted into the script:
; ReadFile
; Ping
; xlLib
; WMISvcMgr

; good coders declare their vars here... ;)

; Prepare Excel
$oXL = xlInit()                   ; initialize Excel
xlBookCreate(xlBookCreate($oXl,1) ; create a workbook

; verify function syntax
$Hosts = ReadFile('myListOfHosts.txt')

$Row = 2  ; row of first Excel data, after any headers

; enumerate hosts
For Each $Host in $Hosts
  If Ping($Host)    ; got a ping reply, so do effective test
    $Junk = WMISvcMgr('list',,,$Host)
    If Not @ERROR   ; got a reply, so computer is alive *1
      $Data = $Host, 'Responds'
      xlRangeValue($oXl, 'A'+CStr($Row), $Data) ; write in Col A, starting in $Row
      $Row = $Row + 1  ; increment row pointer
    EndIf
  Else                 ; no response at all
    $Data = $Host, 'Fails'
    xlRangeValue($oXl, 'A'+CStr($Row), $Data)
    ; might want to consider formatting the data - red text for fail?
    $Row = $Row + 1  ; increment row pointer
  EndIf
Next
; prolly want to write some header cells before you exit
xlFile($oXL, 1, 'log.xls')       ; write the excel file
xlQuit($oXl)                     ; close the excel session
_________________________
Actually I am a Rocket Scientist! \:D