Jump to content
Sign in to follow this  

First Run command being closed after next RunWait command completes

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>

$hGUI = GUICreate("Remote Connection",205,286,192,114)
$hBut1 = GUICtrlCreateButton("Launch Term1",16,48,161,49)
$hBut2 = GUICtrlCreateButton("Launch Term2",16,113,161,49)
GUICtrlSetOnEvent($hBut1, "lnchTerm1Press")

; This while/wend keeps the gui open
While 1

; Functions

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

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

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

; Exit program function (closes plink sessions on the way out)
Func ExitGUI()

Share this post

Link to post
Share on other sites

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!

Share this post

Link to post
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

Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.