Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > To Ping or not to Ping...


Reply
 
Thread Tools Display Modes
  #1  
Old 08-01-2002, 03:50 PM
Writer
Guest
 
Posts: n/a
Question To Ping or not to Ping...


Hi!

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... :-)

-Writer-

Last edited by Robby; 08-01-2002 at 04:48 PM.
Reply With Quote
  #2  
Old 08-01-2002, 04:00 PM
reboot's Avatar
reboot reboot is offline
Keeper of foo

Retired Moderator
* Guru *
 
Join Date: Nov 2001
Location: Graceland
Posts: 15,612
Default

If you want to ping on any Windows version, you need to use the api from icmp.dll
Reply With Quote
  #3  
Old 08-01-2002, 04:00 PM
BillSoo's Avatar
BillSoo BillSoo is offline
Code Meister

Retired Moderator
* Guru *
 
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
Default

I just skimmed your code....you can use GetSystemDirectory API function to return the path of your system directory. Similarily, GetWindowsDirectory returns the path to windows.
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
Reply With Quote
  #4  
Old 08-01-2002, 04:02 PM
OnErr0r's Avatar
OnErr0r OnErr0r is offline
Obsessive OPtimizer

Administrator
* Guru *
 
Join Date: Jun 2002
Location: Debug Window
Posts: 13,685
Default

man.. that looks like a big jumble from here. Use vb tags and indent your if statements and loops.
__________________
Quis custodiet ipsos custodues.
Reply With Quote
  #5  
Old 08-02-2002, 01:12 PM
Writer
Guest
 
Posts: n/a
Question

Reboot,

Quote:
If you want to ping on any Windows version, you need to use the api from icmp.dll
Interesting. Can you provide an example? :-)

-Chris-
Reply With Quote
  #6  
Old 08-02-2002, 01:18 PM
illsorted
Guest
 
Posts: n/a
Default VBNet

Check out this link for a good example:

http://www.mvps.org/vbnet/index.html...ernet/ping.htm
Reply With Quote
  #7  
Old 08-02-2002, 01:25 PM
Writer
Guest
 
Posts: n/a
Default

Bill,

Quote:
I just skimmed your code....you can use GetSystemDirectory API function to return the path of your system directory. Similarily, GetWindowsDirectory returns the path to windows.
I just re-read my initial post, and I noticed that I didn't provide much detail about the issue. Oops. :-) I should have mentioned that I am able to retrieve the system directory path.

The issue seems to be specific to how the result is being captured into the SFilePing variable and then processed when I execute the program. That is, Ping.exe does not launch. I'm wondering if I should add an instruction that will parse ping.exe from SFilePing and then execute it. The question is: how do I do that? :-)

-Writer-
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->