#Region ;**** Directives created by AutoIt3Wrapper_GUI **** #AutoIt3Wrapper_outfile=testing stdout5.exe #AutoIt3Wrapper_Run_Tidy=y #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** ; http://www.autoitscript.com/forum/index.php?s=&showtopic=12828&view=findpost&p=88305 ; A script for AutoIt3. Jon is The Man. ; Script generated by AutoBuilder 0.5 Prototype. CyberSlug rocks. ; Edited with SciTE and Tidy. Go JdeB. #include Dim $ourProcess Dim $username Dim $password Dim $loop GUICreate("STDIO Window", 425, 322, (@DesktopWidth - 425) / 2, (@DesktopHeight - 362) / 2, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS) ; Create a read-only edit control $eOutput = GUICtrlCreateEdit("", 0, 10, 423, 250, BitOR($ES_WANTRETURN, $WS_VSCROLL, $WS_HSCROLL, $ES_AUTOVSCROLL, $ES_AUTOHSCROLL, $ES_READONLY)) ; Ping spawn button $bSSH = GUICtrlCreateButton("SSH", 260, 285, 60, 20) ; Notepad spawn button ;$bNotepad = GuiCtrlCreateButton("Notepad", 180, 285, 60, 20) ; Exit button $bExit = GUICtrlCreateButton("Exit", 340, 285, 60, 20) ; Show the GUI window GUISetState() JDs_debug("Vnc2Me - GUI Starting") ; Loop and update the edit control unitl we hit EOF (and get an error) While 1 ; We assign the process ID of ping to $ourProcess below... If $ourProcess Then ; Calling StdoutRead like this returns the characters waiting to be read $ReadCharsWaiting = StdoutRead($ourProcess, 0, 1) ; Calling StderrRead like this returns the characters waiting to be read If @error = -1 Then JDs_debug("Vnc2Me - STDOUT unable to be read") ; Set $ourProcess to zero so we don't try to read nothing... $ourProcess = 0 MsgBox(0, "App Exited", "Process has exited...") ; ContinueLoop means "don't exit the While loop, just start over without doing anything else" ContinueLoop EndIf $ErrCharsWaiting = StderrRead($ourProcess, 0, 1) ; If there was an error reading, the most likely cause us that the child process has quit... If @error = -1 Then JDs_debug("Vnc2Me - STDERR unable to be read") ; Set $ourProcess to zero so we don't try to read nothing... $ourProcess = 0 MsgBox(0, "App Exited", "Process has exited...") ; ContinueLoop means "don't exit the While loop, just start over without doing anything else" ContinueLoop EndIf ; Since we got here there was no error, but were there characters to be read? If $ReadCharsWaiting Then ; Read all available $currentRead = StdoutRead($ourProcess) $Vnc2MeReadUsername = StringRegExp($currentRead, ".*ogin.*") $Vnc2MeReadPassword = StringRegExp($currentRead, ".*assword.*") If $Vnc2MeReadUsername = 1 Then JDs_debug("Vnc2Me - AUTH - 'login' detected") Vnc2MeUsername() ContinueLoop ElseIf $Vnc2MeReadPassword = 1 Then JDs_debug("Vnc2Me - AUTH - 'password' detected") Vnc2MePassword() ContinueLoop Else ; Add what we read to the editbox GUICtrlSetData($eOutput, $currentRead, 1) JDs_debug("Vnc2Me - STDOUT updates fed to GUI") EndIf Sleep(100) ElseIf $ErrCharsWaiting Then ; Read all available $currentErr = StderrRead($ourProcess) $Vnc2MeErrHostKey = StringRegExp($currentErr, ".*host key is not cached.*") If $Vnc2MeErrHostKey = 1 Then JDs_debug("Vnc2Me - STDERR Host key no cached") Vnc2MeAddHostKey() ; GUICtrlSetData($eOutput, $currentErr, 1) ContinueLoop Else GUICtrlSetData($eOutput, $currentErr, 1) JDs_debug("Vnc2Me - STDERR updates fed to GUI") EndIf EndIf ; => no program output waiting. Else ; => $ourProcess not exist. JDs_debug("Vnc2Me - SSH process not started") Sleep(200) EndIf ; => End $ourProcess ; Get any messages from the GUI $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE ; X button on window was clicked JDs_debug("Vnc2Me - GUI exiting (windows closed)") Vnc2MeExit() Case $msg = $bExit ; Exit button was clicked JDs_debug("Vnc2Me - GUI exiting (exit button)") Vnc2MeExit() Case $msg = $bSSH ; SSH button was clicked JDs_debug("Vnc2Me - SSH button pressed") ; Run child process and provide console i/o for it. ; 1 ($STDIN_CHILD) = Provide a handle to the child's STDIN stream ; 2 ($STDOUT_CHILD) = Provide a handle to the child's STDOUT stream ; 4 ($STDERR_CHILD) = Provide a handle to the child's STDERR stream $ourProcess = Run("jdsplink.exe -C -L 25501:127.0.0.1:5500 -R 5500:127.0.0.1:5900 somehost.com -v", @ScriptDir, @SW_MINIMIZE, 7) JDs_debug("Vnc2Me - SSH process started") ; Case $msg = $bNotepad ; JDs_debug("Vnc2Me - Notepad button pressed") ; ; Notepad button was clicked ; Run("notepad.exe", @SystemDir) Case Else ;;; EndSelect WEnd JDs_debug("Vnc2Me - ") Func Vnc2MeUsername($username = "") ;if $username not passed in func call, ask for it. If $username = "" Then $username = InputBox("username", "Enter username") If @error = 1 Then Exit EndIf EndIf ;writes "login" JDs_debug("Vnc2Me - AUTH - Passing username") StdinWrite($ourProcess, $username & " " & @CR) EndFunc ;==>Vnc2MeUsername Func Vnc2MePassword($password = "") ;if $password not passed in func call, ask for it. If $password = "" Then $password = InputBox("password", "Enter password for " & $username, '', '*') If @error = 1 Then Exit EndIf EndIf ;writes "password" JDs_debug("Vnc2Me - AUTH - Passing password") StdinWrite($ourProcess, $password & " " & @CR) EndFunc ;==>Vnc2MePassword Func Vnc2MeAddHostKey() ;Add Host key to knownhosts JDs_debug("Vnc2Me - STDERR found") $msgbox = MsgBox(4, "The host is not cached", "This Host is not known, do you want to add it to known hosts ???") If $msgbox = 6 Then StdinWrite($ourProcess, "y " & @CR) EndIf EndFunc ;==>Vnc2MeAddHostKey Func Vnc2MeExit() GUICtrlSetData($eOutput, @CRLF & "Exiting" & @CRLF, 1) StdinWrite($ourProcess, "exit" & @CR) Sleep(2000) ProcessClose("jdsplink.exe") Exit EndFunc ;==>Vnc2MeExit Func JDs_debug($msg) DllCall("kernel32.dll", "none", "OutputDebugString", "str", $msg) EndFunc ;==>JDs_debug