bpneiman Posted January 12, 2009 Posted January 12, 2009 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.
bpneiman Posted January 12, 2009 Author Posted January 12, 2009 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.
DjDeep00 Posted January 12, 2009 Posted January 12, 2009 (edited) @bpneiman... You should be able to auto-login to your SSH server by downloading the PuTTYgen from here and following these steps. Edited January 12, 2009 by DjDeep00
bpneiman Posted January 12, 2009 Author Posted January 12, 2009 @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.
LurchMan Posted January 12, 2009 Posted January 12, 2009 (edited) 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 January 12, 2009 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.
bpneiman Posted January 13, 2009 Author Posted January 13, 2009 (edited) 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 January 13, 2009 by bpneiman
azure Posted January 13, 2009 Posted January 13, 2009 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.
bpneiman Posted January 13, 2009 Author Posted January 13, 2009 (edited) 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 January 13, 2009 by bpneiman
azure Posted January 13, 2009 Posted January 13, 2009 (edited) 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 StringLowerOr "SendCapslockMode" Option.Or SEND("{SHIFTDOWN}{SHIFTUP}")Or SEND("{CAPSLOCK off}") Edited January 13, 2009 by azure
bpneiman Posted January 13, 2009 Author Posted January 13, 2009 Try StringUpper and StringLowerOr "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.
azure Posted January 13, 2009 Posted January 13, 2009 Use ControlSend.. i was just giving examples in SEND.. but ControlSend has the same syntax with the text you're sending.
bpneiman Posted January 13, 2009 Author Posted January 13, 2009 Use ControlSend.. i was just giving examples in SEND.. but ControlSend has the same syntax with the text you're sending.I have been using ControlSend, the problem still exists when the PC is locked.
azure Posted January 13, 2009 Posted January 13, 2009 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.
bpneiman Posted January 13, 2009 Author Posted January 13, 2009 $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.
cramaboule Posted January 13, 2009 Posted January 13, 2009 (edited) 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 January 13, 2009 by cramaboule My Autoit programs: MAC Address - - Delete Temp Files - - Ping Test - - Play Video with VLC full screen dual monitors - - Set IP - - Pics Converter - - AutoUpdater - - CPU Usage - - Ending Script Nicely - - GDI+ GUI crossfades (slide transitions) - - Beamer - - Search and Search in Files - - Silent Ninite Others: Export Icons into Dll - - My website
bpneiman Posted January 13, 2009 Author Posted January 13, 2009 Problem seems to be with PuTTY. I was able to get it to work with Hyperterminal, which works just fine for my needs. Thanks to everyone that provided help.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now