Jump to content

Automated PuTTY telnet login help


 Share

Recommended Posts

I need a script that will initiate a PuTTY telnet login session, enter user id and password, and run one command. The PC this is running on will most often be locked, and from searching the forum, I have found I may need to use the ControlSend function because of this. I can start the PuTTY session without problem but I do not understand the syntax of the ControlSend function. I can get it to work fine when the user is logged in.

Pretty straight forward.

Run("c:\putty.exe telnet:99.99.99.99:23")

WinActivate("99.99.99.99 - PuTTY")

WinWaitActive("99.99.99.99 - PuTTY")

Then I need to send user id.

wait

Send passord

wait

Enter command.

Any help is appreciated.

Link to comment
Share on other sites

I can get it to run with the user logged in using:

Run("c:\putty.exe telnet:99.99.99.99:23")
WinWaitActive("99.99.99.99 - PuTTY")
WinWait("99.99.99.99 - PuTTY")

Sleep(2000)
ControlSend("99.99.99.99 - PuTTY","","", "UserName")

Sleep(2000)
ControlSend("99.99.99.99 - PuTTY","","", "{ENTER}")

Sleep(2000)
ControlSend("99.99.99.99 - PuTTY","","", "Password")

Sleep(2000)
ControlSend("99.99.99.99 - PuTTY","","", "{ENTER}")

Sleep(2000)
ControlSend("99.99.99.99 - PuTTY","","", "Command")

; Sleep(2000)
; ControlSend("99.99.99.99 - PuTTY","","", "{ENTER}")

But not when the computer is locked.

Again, any help is appreciated.

Link to comment
Share on other sites

@bpneiman... You should be able to auto-login to your SSH server by downloading the PuTTYgen from here and following these steps.

:)

It is a telnet session. We run a program on the telnet sever at scheduled intervals that downloads files to a folder on the PC. The problem is that the last run of the day occurs after hours and the computer is automatically locked out. We are currently running the program with macro recorder/playback software, but that also does not function when the computer is locked. We have worked around it by setting the computer screen saver lockout to 2 hours. I would rather set it back to 30 mins. for security reasons. I was hoping to be able to get a script to run while the computer was locked using AutoIT.

Link to comment
Share on other sites

you could try using psexec in combination with autoit. If i remember correctly psexec works if the computer has been locked, as long as u have admin rights on it.

Edit: If all your trying to do is run a program on that machine anyways....

Edited by LurchMan

Dating a girl is just like writing software. Everything's going to work just fine in the testing lab (dating), but as soon as you have contract with a customer (marriage), then your program (life) is going to be facing new situations you never expected. You'll be forced to patch the code (admit you're wrong) and then the code (wife) will just end up all bloated and unmaintainable in the end.

Link to comment
Share on other sites

you could try using psexec in combination with autoit. If i remember correctly psexec works if the computer has been locked, as long as u have admin rights on it.

Edit: If all your trying to do is run a program on that machine anyways....

I think we are making this more complicated than it needs to be. All I need to do is open a telnet session on the local locked computer, enter user id and password, and run one command. The command that is run takes care of the rest. I can open the telnet session, I just cannot get around entering the user id, password, and command when the PC is locked.

I am telnetting into a Unix box.

Edited by bpneiman
Link to comment
Share on other sites

The problem is that you're using WinActive and WinWaitActive.

When the computer's locked, there are no active windows, so it will wait forever.

Try using WinExists and ControlSends/Clicks rather than Sends.

You need to use commands that don't require the window to be active.

Link to comment
Share on other sites

The problem is that you're using WinActive and WinWaitActive.

When the computer's locked, there are no active windows, so it will wait forever.

Try using WinExists and ControlSends/Clicks rather than Sends.

You need to use commands that don't require the window to be active.

BINGO! This works. My next questing is, how do I specify what case the commands are entered in, independent of the caps lock? The user id and password need to be in lowercase, the command that is run needs to be in uppercase.

Again, thank you for all the help.

Edited by bpneiman
Link to comment
Share on other sites

BINGO! This works. My next questing is, how do I specify what case the commands are entered in, independent of the caps lock? The user id and password need to be in lowercase, the command that is run needs to be in uppercase.

Again, thank you for all the help.

Try StringUpper and StringLower

Or "SendCapslockMode" Option.

Or SEND("{SHIFTDOWN}{SHIFTUP}")

Or SEND("{CAPSLOCK off}")

Edited by azure
Link to comment
Share on other sites

Try StringUpper and StringLower

Or "SendCapslockMode" Option.

Or SEND("{SHIFTDOWN}{SHIFTUP}")

Or SEND("{CAPSLOCK off}")

I have been trying those, but they don't seem to be working when the computer is locked. When the user is logged in, they work fine. I can set the case or turn caps lock off/on, but not when the PC is locked.

Link to comment
Share on other sites

I have been using ControlSend, the problem still exists when the PC is locked.

$wintitle = "Untitled - Notepad"
$program = "notepad.exe"
Run($program)
WinWait($wintitle)

;Sleep(2000)
ControlSend($wintitle,"","", StringUpper("UserName"))

;Sleep(2000)
ControlSend($wintitle,"","", "{ENTER}")

;Sleep(2000)
ControlSend($wintitle,"","", StringUpper("Password"))

;Sleep(2000)
ControlSend($wintitle,"","", "{ENTER}")

;Sleep(2000)
ControlSend($wintitle,"","", StringLower("Command"))

; Sleep(2000)
; ControlSend($wintitle,"","", "{ENTER}")

This worked fine for me while my computer was locked. Not sure what problem you're having.

Link to comment
Share on other sites

$wintitle = "Untitled - Notepad"
$program = "notepad.exe"
Run($program)
WinWait($wintitle)

;Sleep(2000)
ControlSend($wintitle,"","", StringUpper("UserName"))

;Sleep(2000)
ControlSend($wintitle,"","", "{ENTER}")

;Sleep(2000)
ControlSend($wintitle,"","", StringUpper("Password"))

;Sleep(2000)
ControlSend($wintitle,"","", "{ENTER}")

;Sleep(2000)
ControlSend($wintitle,"","", StringLower("Command"))

; Sleep(2000)
; ControlSend($wintitle,"","", "{ENTER}")

This worked fine for me while my computer was locked. Not sure what problem you're having.

This works great for me also in Notepad when the computer is locked. It is not working in PuTTY, a terminal emulation program. In PuTTY (with the computer locked), the character case is set to whatever state the keyboard is in.

Odd.

Link to comment
Share on other sites

Hi try this

Run(@ComSpec & " /c putty.exe -ssh -2 -P 123 root@123.123.123.123 -pw 1234", "",@SW_HIDE)
     Opt("WinTitleMatchMode", 2)   ;1=start, 2=subStr, 3=exact, 4=advanced, -1
     Sleep(2000)
     WinWaitActive("PuTTY")
     Sleep(200)
     If 0=1 Then
    ;for test
         Send("ls{ENTER}")
         Send("^d^d")
     Else
         Send("init 0{ENTER}")
         Send("^d^d")
     EndIf
     Exit

I use this script to switch off one of my Server...

EDIT: misstyping

Edited by cramaboule
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...