Jump to content

Using AutoIt to control putty

Recommended Posts

putty is a telnet client, although I'm sure most of you know that.

You input the ip address of the computer your sending the commands to, and putty opens a window that is named " 'ip address' - putty "

That would be fine if I was using the script for one ip address but i am not.

I was thinking that autoit can ask me for the ip address then use the ip address I input to launch putty and also use the ip address as a variable to control the window, but I can't figure out how to do that.

here are some screen caps from putty so that you can get a better idea:

Posted Image

Posted Image

Posted Image

Only problem is, I don't know how to do that. lol.

Any help would be appreciated.

Link to post
Share on other sites
  • 5 weeks later...

One way to do it is log onto the system and allow putty to accept the key. Afterwards the authentication box will no longer appear. I have scripted a few AutoIT scripts because we do a lot of remote administration of Unix systems and use putty on a daily basis with dozens of different servers.

Func do_backup()
    Send("cd dba ; tail `ls -tr *backup* | tail -1` | (grep Finished && ls -ltr *backup*) || (tail -f `ls -tr *backup* | tail -1`){ENTER}")

Func get_idpw()
#region --- GuiBuilder code Start ---
; Script generated by AutoBuilder 0.6 Prototype

    GuiCreate("Enter ID/Password", 197, 110,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))

    $Input_id = GuiCtrlCreateInput("Input1", 80, 20, 110, 20)
    $Label_2 = GuiCtrlCreateLabel("ID", 10, 20, 40, 20)
    $Label_3 = GuiCtrlCreateLabel("Password", 10, 50, 60, 20)
    $Input_pw = GuiCtrlCreateInput("Input4", 80, 50, 110, 20)
    $Button_5 = GuiCtrlCreateButton("OK", 50, 80, 60, 20)

    While 1
        $msg = GuiGetMsg()
        Case $msg = $GUI_EVENT_CLOSE
        case $msg = $Button_5
        Case Else

    $id = GUICtrlRead($Input_id)
    $pw = GUICtrlRead($Input_pw)

#endregion --- GuiBuilder generated code End ---


Func send_idpw()
    Send( $id & "{ENTER}" )
    Sleep (3000)
    Send( $pw & "{ENTER}" )
    Sleep (3000)

Of course this only works when the putty window is active, next step is to incorporate plink into AutoIT.

Edited by cpuobsessed
Link to post
Share on other sites
  • 5 years later...

my sample, not read window..... conect on

$user = "root"
$password =""
$host =""
$port ="22"

$puty_exe = @ScriptDir & "\putty.exe"; putty salve local folder script

; putty -ssh -l usuario p "port" -pw senha


$command = RunWait(@comspec & " /C "&$puty_exe&" -ssh -l "&$user&" "&$host&" p "&$port&" -pw "&$password,@ScriptDir, @SW_HIDE, 1)
;$command = RunWait(@comspec & " /C "&$puty_exe&" system scripts run mario",@ScriptDir, @SW_HIDE, 1)
While 1
$data = StdoutRead($command)
If @error Then ExitLoop


Att...Cleber Antônio Made in Bio zonte Minas Gerais  :sweating:

Link to post
Share on other sites

God save the resurrection.


OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control


Link to post
Share on other sites
  • 11 months later...
  • Moderators


We ask peopel not to necro-post for two main reasons:

- 1. The language advances and the functionality might well be included in core or UDF code by now.

- 2. The changes in language syntax mean that it is likely that code from more than a couple of years ago may well not run under the current release interpreter without significant modification.

Clear enough? :)


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:


ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area


Link to post
Share on other sites
  • 4 years later...
  • 11 months later...

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
  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...