[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 246
  • Last Modified:

I am using Visual Basic for Applications (Excel) to validate an IP Host is live before attempting any network related functions.

(Im a new programmer, so please bare with me :) )
I would prefer to use the shell function to run ping and redirect the output to a text file.
when I have attempted to this.
1. the ping command runs fine.
2. it does not write out to a text file... here is my code:

Private Sub CommandButton1_Click()
 IP = "127.0.0.1"
 COMND = "PING -N 1 127.0.0.1 > C:\TEST.TXT"
 PING = COMND & " " & IP
 bla = shell(PING)
End Sub

Another method I tried with the shell function was to call a batch file.
The Batch file contains the following code:

@ECHO OFF
PING -N 1 127.0.0.1 > C:\TEST.TXT

When ran from a command prompt this batch file works...however, if I try using the shell function as follows....

bla = shell("c:\pingip.bat")

It does not run the batch file.

any help on this would be greatly appreciated.

0
bitshredder
Asked:
bitshredder
1 Solution
 
DabasCommented:
Hi bitshredder:
>  PING = COMND & " " & IP
This will cause the PING variable to have PING -N 1 127.0.0.1 > C:\TEXT.TXT 127.0.0.1
which is not what you want!

Dabas
0
 
DabasCommented:
bitshredder:
> bla = shell("c:\pingip.bat")
Shell works differently depending on the operating system you are on.
What is your OS?

Dabas
0
 
DabasCommented:
bitshredder:
> PING -N 1 127.0.0.1 > C:\TEST.TXT
Seems the option is case sensitive. On my system (XP) this only worked with lower case -n

Dabas
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
hesCommented:
Dabas is correct try:

Private Sub CommandButton1_Click()
 IP = "127.0.0.1"
 COMND = "ping -n 1 " & IP & " > C:\TEST.TXT"
 bla = shell(COMND)
End Sub
0
 
mugman21Commented:
BitShreder,

Here is a link to an open source control that will send and receive messages to and from command based applications such as ping.exe. The below link has all the source, to the redirect dll, and an example of how to use it in Visual Basic 6. This is easy to use, and is a really great open source project. Using this, it will do EXACTLY what you need to do (and more). Check it out, you wont be sorry. (the example will put the data you want into text boxes, or any other type of control you wish)

 http://users.skynet.be/saw/redirect.htm

Mugman

P.S. This control is a great way to give old dos programs like IPConfig, Ping, and TraceRT a grafical user interface.
0
 
bitshredderAuthor Commented:
okay cool Dabas was right on the first try,
It ended up being a captial 'N' for the ping parameter, when it should have been a lowercase 'n'.
thanks for the help in correcting me on this. 8รพ
-rich ;-)
0
 
DabasCommented:
Rich:
I understand this is your first post.
I suggest you close the question by accepting the post with the answer.
Thanks

Dabas
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now