I maintain a GUI based, "Ping" program that allows end-users to run the Ping.exe utility against multiple nodes and display the results within a text box. The current program version is exclusive to Windows NT 4.0/2000 due to a hardcoded reference to ping.exe.
I'm now trying to re-write the existing hardcoded code so that "Ping" will run any Windows based system that contains system32\ping.exe. I thought the quick and easy fix would simply involve pulling the system folder path using an environment reference and then combining the result with "\system32" and "\ping.exe." This is where I'm running into a jam. I'm sure I'm missing an obvious step, but my brain is near scrambled at this point. :-D
The code (in bold text) I'm trying to re-write exists within the following sub routine:
Code:
Private Sub cmdPink_Click()
cmdClear_Click
If FileName = "" Then
MsgBox "Select a Text file, and Click PING.", _
vbOKOnly, "Error!"
Exit Sub
End If
MousePointer = 11
ReDim sStatus(iLoop) As String
Dim rc As Integer
Dim sFilePing As String
Dim FileNum As Integer
Dim sTemp As String
Dim bGetResult As Boolean
Dim iTotal As Integer
iTotal = iLoop
[B][B]sFilePing = "c:\winnt\system32\ping.exe "[/B][/B]
[B][B]If Dir(sFilePing) = "" Then
MsgBox "The system can't find ping.exe. Please select it manually.", vbOKOnly, "Error!"
sFilePing = GetFile
End If[/B][/B]
FileNum = FreeFile
bGetResult = False
iLoop = 0
While (iLoop < iTotal)
'While (iLoop < 6)
rc = Shell(Environ$("comspec") & " /c " & sFilePing & _
sMachineName(iLoop) & " > " & sResultFile, 0)
Pause (rc)
Open sResultFile For Input As FileNum
While Not (EOF(FileNum) Or bGetResult)
Input #FileNum, sTemp
If InStr(1, sTemp, "reply from", 1) Then
sStatus(iLoop) = "Active."
bGetResult = True
ElseIf InStr(1, sTemp, "bad ip address", 1) Then
sStatus(iLoop) = "Bad IP Address."
bGetResult = True
ElseIf InStr(1, sTemp, "unknown host", 1) Then
sStatus(iLoop) = "Bad IP Address."
bGetResult = True
ElseIf InStr(1, sTemp, "timed out", 1) Then
sStatus(iLoop) = "Not Active."
bGetResult = True
End If
DoEvents
Wend
Close FileNum
txtResult.Text = txtResult.Text & sMachineName(iLoop) & vbNewLine
'" : " & sstatus(iLoop) & vbNewLine
txtStatus.Text = txtStatus.Text & sStatus(iLoop) & vbNewLine
bGetResult = False
iLoop = iLoop + 1
Label1.Caption = iLoop & " / " & iTotal
Wend
MousePointer = 0
Beep
End Sub
-----------------------------------------------------------------------------------
Here's Writer's version:
Private Sub cmdPink_Click()
cmdClear_Click
If FileName = "" Then
MsgBox "Select a Text file, and Click PING.", _
vbOKOnly, "Error!"
Exit Sub
End If
MousePointer = 11
ReDim sStatus(iLoop) As String
Dim rc As Integer
[B][B]Dim PingPath As String[/B][/B]
Dim sFilePing As String
Dim FileNum As Integer
Dim sTemp As String
Dim bGetResult As Boolean
Dim iTotal As Integer
iTotal = iLoop
[B][B]PingPath = Environ("windir") & "\SYSTEM32" & "\ping.exe"[/B][/B]
[B][B]sFilePing = PingPath[/B][/B]
FileNum = FreeFile
bGetResult = False
iLoop = 0
While (iLoop < iTotal)
'While (iLoop < 6)
rc = Shell(Environ$("comspec") & " /c " & sFilePing & _
sMachineName(iLoop) & " > " & sResultFile, 0)
Pause (rc)
Open sResultFile For Input As FileNum
While Not (EOF(FileNum) Or bGetResult)
Input #FileNum, sTemp
If InStr(1, sTemp, "reply from", 1) Then
sStatus(iLoop) = "Active."
bGetResult = True
ElseIf InStr(1, sTemp, "bad ip address", 1) Then
sStatus(iLoop) = "Bad IP Address."
bGetResult = True
ElseIf InStr(1, sTemp, "unknown host", 1) Then
sStatus(iLoop) = "Bad IP Address."
bGetResult = True
ElseIf InStr(1, sTemp, "timed out", 1) Then
sStatus(iLoop) = "Not Active."
bGetResult = True
End If
DoEvents
Wend
Close FileNum
txtResult.Text = txtResult.Text & sMachineName(iLoop) & vbNewLine
'" : " & sstatus(iLoop) & vbNewLine
txtStatus.Text = txtStatus.Text & sStatus(iLoop) & vbNewLine
bGetResult = False
iLoop = iLoop + 1
Label1.Caption = iLoop & " / " & iTotal
Wend
MousePointer = 0
Beep
End Sub
----------------------------------------------------------------------------------
Note: I removed the condition check after the SFilePing assignment because I'm mulling over how I want to re-write the condition.
Help... :-)