Jump to content

First Run command being closed after next RunWait command completes


smcan
 Share

Go to solution Solved by smcan,

Recommended Posts

I have a script that launches plink.exe followed by portqry.exe that checks to make sure the plink created tunnel has been established and then opens mstsc.exe with a preconfigured .RDP file when portqry returns successful (Thanks to orbs for helping get the portqry looping fixed).

However, after the RunWait for portqry completes and exits, the running plink is also being closed and the end result is the mstsc can't connect because the tunnel is no longer there.

Following is the entire script (not entirely complete and sanitized ip's/domain/accounts).  Hoping somebody can advise why plink doesn't keep running?

#include <GUIConstantsEx.au3>
#include <EditConstants.au3>

Opt("GUIOnEventMode",1)
$hGUI = GUICreate("Remote Connection",205,286,192,114)
$hBut1 = GUICtrlCreateButton("Launch Term1",16,48,161,49)
$hBut2 = GUICtrlCreateButton("Launch Term2",16,113,161,49)
GUISetState(@SW_SHOW)
GUICtrlSetOnEvent($hBut1, "lnchTerm1Press")
GUISetOnEvent($GUI_EVENT_CLOSE, "ExitGUI")

; This while/wend keeps the gui open
While 1
    Sleep(10);
Wend

; Functions

; If Launch term1 button is pressed
func lnchTerm1Press()
If lnchTerm1() Then
    MsgBox(0, "YIL", "Yey, we are connected!", 10)
Else
    MsgBox(0, "SOL", "No tunnel created, sorry!", 10)
Endif
EndFunc

; Launch Term1 button function
Func lnchTerm1()
    $uName = "sshuser"
    $pWord = "sshpass"
    Run("plink.exe -l " & $uName & " -pw " & $pWord & " -L 3391:192.168.50.25:3389 -P 22 -2 -C -ssh ssh.domain.tld","",@SW_SHOW)
    $intCtr = 1
    while $intCtr < 30
        $retVal = RunWait("portqry.exe -n 127.0.0.1 -e 3391","",@SW_SHOW)
        if $retVal = 0 Then
            Run("mstsc.exe Term1.RDP")
            Return True
        Else
            $intCtr = $intCtr + 1
        EndIf
    WEnd
    Return False
EndFunc

; Close all plink processes function
Func PlinkClose()
    ;Close any open plink sessions
    While 1
        if ProcessExists("plink.exe") Then
            ProcessClose("plink.exe")
        Else
            return False
        EndIf
    Wend
EndFunc

; Exit program function (closes plink sessions on the way out)
Func ExitGUI()
    PlinkClose();
    Exit
EndFunc
Link to comment
Share on other sites

  • Solution

Think I figured it out but it's not optimal.  Looks like the problem is with plink.exe itself and not with the autoit code.  I'm using a portable version of plink (stores keys and session info in files instead of registry) but I don't think that matters because the portable version is still based on the most recent version 0.63 of regular plink.  Using Putty instead of plink produces the desired result.  Not optimal as I prefer the way plink works on the command line over putty but I'll take it to get this project moving.  Figured out the error that was causing plink to close using the @comspec /k instead of /c.  For some reason plink was receiving a disconnect command when portqry ran but putty doesn't seem to have the same issue.

Thanks again to orbs for helping me get the portqry loop working properly!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...