View Single Post
Old 03-12-2019, 11:52 AM
berdmann berdmann is offline
VanDyke Technical Support
Join Date: Aug 2017
Posts: 441
Hi GuitarDude,

I stumbled upon this example, in which the ping will run continuously in CMD until you press CTRL+C

' Attempt to set strHost to some common-sense default
' values... first, see if anything is in the clipboard...
strHost = crt.Clipboard.Text
' If not, see if anything is selected in the terminal window...
If strHost = "" Then strHost = crt.Screen.Selection

' Set up a default command to run. If the button mapped to
' run this script doesn't have any arguments, then this will
' be what is launched...
strCmd = "cmd /C ping __HOST__ -t"
if crt.Arguments.Count > 0 Then
    strCmd = crt.Arguments(0)
end if

Sub Main()
    ' Prompt the individual for input as to what to use for __HOST__:
    ' strHost = crt.Dialog.Prompt("Command to run is:" & vbcrlf & vbcrlf & _
    '    vbtab & strCmd & vbcrlf & vbcrlf & _
    '    "What host would you like to run the command on?", "Command Runner", strHost)
    ' handle cancel
    strHost = crt.Session.RemoteAddress
    if strHost = "" Then Exit Sub

    ' Replace __HOST__ with what was supplied...
    strCmd = Replace(strCMD, "__HOST__", strHost)

    ' Now, run the command and tap into stdout...reading all the data until it exits...
    Set g_shell = CreateObject("WScript.Shell")
    ' replace /C with /K to keep CMD window open
    strCmd = Replace(strCMD, "/C", "/K")
    g_shell.Run strCmd

End Sub

VanDyke Software
Technical Support
(505) 332-5730