How to Ping a remote server from a command button

D

DetRich

Hello,

I have a form/sub-form displaying info on individual servers. I would like
to be able to click a button and ping the current remote server. I don't
want to open a command prompt and issue a ping command. I want this to occur
in the background and then report if the remote server responds.

Can anyone tell me how this might be accomplished?

Thanks very much,
DetRich
 
D

dhstein

You can run a batch job as shown below. Your batch job can ping the server
and put output to a file which you can read. You can then report the results
to the user.


Private Sub cmdPing_Server_Click()

RunJob "C:\BATCH\PINGSERV.BAT"
End Sub

Sub RunJob(Command As String)

Dim varProc As Variant

varProc = Shell(Command, 6)

End Sub
 
D

DetRich

dhstein,

Thanks very much for the reply. that definitely helps.

To expand and make it a little more user-friendly, is there a way to pass
the name of the server to ping to the process? Since the name of the server
in question will be on the current form, how can I dynamically ping that
server? I'm pretty sure I can write the code to read the output file to see
if the ping was successful and present the result to the user.

Thanks again,
DetRich
 
D

Douglas J. Steele

You could using VBA code to rewrite the content of PINGSERV.BAT to include
the server name, but you might find it easier to use the code Randy Birch
has at http://vbnet.mvps.org/code/internet/pingbyhostname.htm

Note that Randy's site is aimed at VB programmers. Due to differences
between forms in VB and in Access, most of Randy's examples won't work
directly in Access without some minor tweaking. In this case, since Access
doesn't support control arrays, you cannot follow his instruction to add
"six text boxes in a control array (Text4(0) - Text4(5))". As well, in
Access, you can only refer to a control's Text property if the control has
focus: use the Value property instead (or simply skip the reference to the
property)
 
D

dhstein

Rich,

The Batch file can accept a parameter so you can call

C:\BATCH\PINGSERV.BAT servername

In the batch file you can do :

ping %1


Having said that, you'll have to experiment on the VBA side to pass the
string containing your server name to the RUNJOB program.

RunJob "C:\BATCH\PINGSERV.BAT"
 
L

LINDA

dhstein said:
You can run a batch job as shown below. Your batch job can ping the
server
and put output to a file which you can read. You can then report the
results
to the user.


Private Sub cmdPing_Server_Click()

RunJob "C:\BATCH\PINGSERV.BAT"
End Sub

Sub RunJob(Command As String)

Dim varProc As Variant

varProc = Shell(Command, 6)

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top