Jump to content

putty and gui


deployk
 Share

Recommended Posts

Hello.

This script does not work. ;) Where wrong. :)

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiIPAddress.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("SSH", 331, 238, 326, 220)
$Group1 = GUICtrlCreateGroup(" SSH Login", 8, 8, 313, 217)
$IP = GUICtrlCreateLabel("IP", 80, 48, 21, 22)
GUICtrlSetFont(-1, 11, 800, 0, "Tahoma")
$IPAddress1 = _GUICtrlIpAddress_Create($Form1, 104, 48, 130, 21)
_GUICtrlIpAddress_Set($IPAddress1, "212.233.209.73")
$User = GUICtrlCreateLabel("User", 64, 96, 39, 22)
GUICtrlSetFont(-1, 11, 800, 0, "Tahoma")
$Username = GUICtrlCreateInput("", 104, 96, 129, 21)
$Password = GUICtrlCreateLabel("Password", 24, 136, 77, 22)
GUICtrlSetFont(-1, 11, 800, 0, "Tahoma")
$Pass = GUICtrlCreateInput("", 104, 136, 129, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_PASSWORD))
$Login = GUICtrlCreateButton("Login", 104, 176, 107, 25)
GUICtrlSetFont(-1, 10, 800, 0, "Tahoma")
$Cancel = GUICtrlCreateButton("Cancel", 232, 176, 75, 25)
GUICtrlSetFont(-1, 10, 800, 0, "Tahoma")
$Label1 = GUICtrlCreateLabel("Port", 240, 48, 36, 22)
GUICtrlSetFont(-1, 11, 800, 0, "Tahoma")
$Input3 = GUICtrlCreateInput("22", 280, 48, 25, 21)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        case $Cancel
            Exit
        case $Login
            
        $IPAddress1 = GUICtrlRead($IPAddress1)
        $Username = GUICtrlRead($Username)
        $Pass = GUICtrlRead($Pass)
        ExitLoop
        
    EndSwitch
WEnd

Run(@ComSpec & " /c putty.exe -ssh -2 -P 22" & $Username & "@" & $IPAddress1 & "-pw" & $Pass & "", @SW_HIDE)
Link to comment
Share on other sites

  • Needed space between 22 and $Username
  • Needed space before and after -pw
  • Changed "$IPAddress1 = GUICtrlRead($IPAddress1)" to "$IPAddress1 = _GUICtrlIpAddress_Get($IPAddress1)"...$IPAddress1 was returning 0 with GUICtrlRead
  • If you used @Comspec with @SW_HIDE, both CMD window and Putty were hidden
Fixed Script
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiIPAddress.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("SSH", 331, 238, 326, 220)
$Group1 = GUICtrlCreateGroup(" SSH Login", 8, 8, 313, 217)
$IP = GUICtrlCreateLabel("IP", 80, 48, 21, 22)
GUICtrlSetFont(-1, 11, 800, 0, "Tahoma")
$IPAddress1 = _GUICtrlIpAddress_Create($Form1, 104, 48, 130, 21)
_GUICtrlIpAddress_Set($IPAddress1, "212.233.209.73")
$User = GUICtrlCreateLabel("User", 64, 96, 39, 22)
GUICtrlSetFont(-1, 11, 800, 0, "Tahoma")
$Username = GUICtrlCreateInput("", 104, 96, 129, 21)
$Password = GUICtrlCreateLabel("Password", 24, 136, 77, 22)
GUICtrlSetFont(-1, 11, 800, 0, "Tahoma")
$Pass = GUICtrlCreateInput("", 104, 136, 129, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_PASSWORD))
$Login = GUICtrlCreateButton("Login", 104, 176, 107, 25)
GUICtrlSetFont(-1, 10, 800, 0, "Tahoma")
$Cancel = GUICtrlCreateButton("Cancel", 232, 176, 75, 25)
GUICtrlSetFont(-1, 10, 800, 0, "Tahoma")
$Label1 = GUICtrlCreateLabel("Port", 240, 48, 36, 22)
GUICtrlSetFont(-1, 11, 800, 0, "Tahoma")
$Input3 = GUICtrlCreateInput("22", 280, 48, 25, 21)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Cancel
            Exit
        Case $Login
            $IPAddress1 = _GUICtrlIpAddress_Get($IPAddress1)
            $Username = GUICtrlRead($Username)
            $Pass = GUICtrlRead($Pass)
            ExitLoop
    EndSwitch
WEnd

$Command = "putty.exe -ssh -2 -P 22 " & $Username & "@" & $IPAddress1 & " -pw " & $Pass
MsgBox(32, 'Command to Pass', $Command & @LF & $IPAddress1) ;comment out this line for production
Run($Command)
Link to comment
Share on other sites

Thanks Varian , this works

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiIPAddress.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#region ### START Koda GUI section ### Form=
$Form1 = GUICreate("SSH", 331, 238, 326, 220)
$Group1 = GUICtrlCreateGroup(" SSH Login", 8, 8, 313, 217)
$IP = GUICtrlCreateLabel("IP", 80, 48, 21, 22)
GUICtrlSetFont(-1, 11, 800, 0, "Tahoma")
$IPAddress1 = _GUICtrlIpAddress_Create($Form1, 104, 48, 130, 21)
_GUICtrlIpAddress_Set($IPAddress1, "212.233.209.73")
$User = GUICtrlCreateLabel("User", 64, 96, 39, 22)
GUICtrlSetFont(-1, 11, 800, 0, "Tahoma")
$Username = GUICtrlCreateInput("", 104, 96, 129, 21)
$Password = GUICtrlCreateLabel("Password", 24, 136, 77, 22)
GUICtrlSetFont(-1, 11, 800, 0, "Tahoma")
$Pass = GUICtrlCreateInput("", 104, 136, 129, 21, BitOR($GUI_SS_DEFAULT_INPUT, $ES_PASSWORD))
$Login = GUICtrlCreateButton("Login", 104, 176, 107, 25)
GUICtrlSetFont(-1, 10, 800, 0, "Tahoma")
$Cancel = GUICtrlCreateButton("Cancel", 232, 176, 75, 25)
GUICtrlSetFont(-1, 10, 800, 0, "Tahoma")
$Label1 = GUICtrlCreateLabel("Port", 240, 48, 36, 22)
GUICtrlSetFont(-1, 11, 800, 0, "Tahoma")
$Input3 = GUICtrlCreateInput("22", 280, 48, 25, 21)
GUICtrlSetState(-1, $GUI_DISABLE)
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
#endregion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Cancel
            Exit
        Case $Login
            $IPAddress1 = _GUICtrlIpAddress_Get($IPAddress1)
            $Username = GUICtrlRead($Username)
            $Pass = GUICtrlRead($Pass)
            ExitLoop
    EndSwitch
WEnd
GUISetState(@SW_HIDE)
RunWait(@ComSpec & " /c putty.exe -ssh -2 -P 22 " & $Username & "@" & $IPAddress1 & " -pw " & $Pass, "", @SW_HIDE)
Edited by deployk
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...