Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I'm trying to write a script with visual basic and wan't to use the dos command:
"Ping (Server) -t"
How do i make this command launch when I press a button?

SkyDomain:
Have a textbox labeled txtCommand.
Have a buttom labeled Command1.Private Sub Command1_Click()
Shell (txtCommand.Text)
End SubWhat ever you type in the txtCommand
box will be executed by the shell if
applicable. For instance: "ping cnn.com"
without the double qoutes will result in the shell pinging cnn.com.Hope this helps.
Infinite Recursion

Thanks Infinite Recursion it woked just great.
My next problem is how can I make a button that terminates the CMD window that opens?

SkyDomain:
Type the title of the window in the textbox and clicking the button will close the window. I suggest "hardcoding" the window name into a string and removing the text box, if the window title doesn't change
often.Infinite Recursion
---------
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Const WM_CLOSE = &H10Private Sub Form_Load()
Dim WinWnd As Long, Ret As String, RetVal As Long, lpClassName As String
'Ask for a Window title
Ret = InputBox("Enter the exact window title:" & vbNewLine & "Note: must be an exact match")
If Ret = "" Then Exit Sub
'Search the window
WinWnd = FindWindow(vbNullString, Ret)
If WinWnd = 0 Then MsgBox "Couldn't find the window ...": Exit Sub
'Post a message to the window to close itself
PostMessage WinWnd, WM_CLOSE, 0&, 0&End Sub

![]() |
MySQL Data Conversion
|
perl drop down menu Oracl...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |