Run a Command Prompt Line Through a Form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

To make this easier I'll explain quick.
We have a internet usage database. People argue their IP Address and saying
it's not them.
I created a Command Button to Open. I then run Ping 123.456.789.123 or the
PC name. The form pulls up username and IP (through scrolling). Is there a
way to make that command prompt automatically ping the lbl that's in there?
Basically I want to click Command Promt and have it bring up CMD and
automatically insert "ping 123.123.123.123".
Thanks
 
What Randy Birch has at
http://vbnet.mvps.org/code/network/hostnamefromip.htm should help you get
the name of the machine associated with the IP. Not sure whether it's
possible to get the ID of the user logged onto the machine.

Obligatory warning: Randy's site is aimed at VB programmers. Because of
significant differences between the controls available to forms in VB and in
Access, some of his examples don't port straight into Access. Having looked
at this example, though, I think you should be okay.
 
jeridbohmann said:
To make this easier I'll explain quick.
We have a internet usage database. People argue their IP Address and
saying it's not them.
I created a Command Button to Open. I then run Ping 123.456.789.123
or the PC name. The form pulls up username and IP (through
scrolling). Is there a way to make that command prompt automatically
ping the lbl that's in there? Basically I want to click Command Promt
and have it bring up CMD and automatically insert "ping
123.123.123.123".
Thanks

I'm not sure I understand exactly what you want, but suppose your form
has a text box named "txtIPAddress". You could have a button named
"cmdPingIt" on the form, with this code:

Private Sub cmdPingIt_Click()

Shell "cmd.exe /k ping " & Me.txtIPAddress", vbNormalFocus

End Sub

Is that what you're looking for?
 
Very-Very Close!
I ran:
Private Sub cmdPingIt_Click()

Shell "cmd.exe /k ping " & "Me.txtIPAddress", vbNormalFocus

End Sub
I had to add quotes in front of "me." otherwise I would get an error.
However, the cmd ran, but tried pinging "me.txtIPAddress", and not what was
in that field.
I ran that code and inserted a PC name in the "Me." portion and it did
exactly that. It just won't pull the data from the field to ping.
 
jeridbohmann said:
Very-Very Close!
I ran:
I had to add quotes in front of "me." otherwise I would get an error.
However, the cmd ran, but tried pinging "me.txtIPAddress", and not
what was in that field.
I ran that code and inserted a PC name in the "Me." portion and it did
exactly that. It just won't pull the data from the field to ping.

Sorry, I made a small typo, adding an unwanted, unmatched quote on the
end of Me.txtIPAddress. That line should have been:

Shell "cmd.exe /k ping " & Me.txtIPAddress, vbNormalFocus

That works for me.
 
Dirk!! You are the man!
Thank you so much...you saved me an easy 30-45 minutes daily confirming
peoples IP Addresses! Yes we have that many users abusing the internet at
work!
Thank you so much for your time!
 
I'm still pretty green with VBA, and used this post to help me with something
I'm doing. Just one question about the shell function, what exactly does the
/K do? (In other posts related to the shell function I've seen /c). I wrote
a shell command based on the command from this post:

Shell "C:\WINNT\System32\cmd.exe /K RENAME ""C:\TCE\PXC0413.THU""
""Patients.TXT""", vbHide

It works, but I don't exactly know what the argument /K does. Is there some
sort of reference for these types of arguments?
 
Dear Matt:

I did this:

Start / Help and Support

In the Search control put cmd.exe.

Select the link for cmd.

The options for the command line of this particular program are then shown.

/k
Carries out the command specified by string and continues.

Tom Ellison
 
Another way you can check the flags for cmd.exe is to use Windows:

Start / Run ... / cmd.exe /?

which will list all the flags available with cmd.exe
 
Back
Top