Cruz Posted September 7, 2005 Share Posted September 7, 2005 Hello all,I am very new to AutoIT (3 days, now) and I need help writing a script that will help make it easier for my colleagues and I login a remote network via a VPN Client and telnet to a specific server using the same credentials. I have the GUI working for the most part. It will login to the VPN client using the username\password supplied by the user via the GUI then once connected it will telnet to the server using the same credentials. As long as the information is correct the program functions but if either the username or password are mistyped the program fails and the user must recover manually.I really need help with how to make the user input for the username stay once the program is closed and reloaded. I would also like to send the telnet program to the systray once it successfully logs in.Please reply if you have any suggestionsThanks Cruzexpandcollapse popup#include <GUIConstants.au3>;Create GUI WindowGUICreate("AutoConnect version 1.0",250,170);Create Help Menu$helpmenu = GuiCtrlCreateMenu ("&Help")$aboutitem = GuiCtrlCreateMenuitem ("&About",$helpmenu)$contactitem = GUICtrlCreateMenuitem ("&Contact",$helpmenu);Create Buttons$loginbutton = GuiCtrlCreateButton ("Login",30,110,70,20, $BS_DEFPUSHBUTTON)$cancelbutton = GuiCtrlCreateButton ("Cancel",150,110,70,20)GuiSetState(); INPUT Username & create username variableGUICtrlCreateLabel("Username:",20,32,70)$username = GUICtrlCreateInput("",80,30,150,20)GUICtrlSetState(-1,$GUI_ACCEPTFILES); INPUT Password & create password variableGUICtrlCreateLabel("Password:",20,62,70)$password = GUICtrlCreateInput("",80,60,150,20,$ES_PASSWORD)GUICtrlSetState(-1,$GUI_ACCEPTFILES)While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Or $msg = $cancelbutton ExitLoop Case $msg = $loginbutton ;Start Nortel VPN Client Run("C:\Program Files\Nortel Networks\Extranet.exe") WinWaitActive("Contivity VPN Client") ControlCommand("Contivity VPN Client","","ComboBox1","SelectString", 'United States, Richardson 1') ControlClick("Contivity VPN Client","",1000) Send("{TAB}") Send(GUICtrlRead($password)) Send("{ENTER}") WinWaitActive("Security Banner") Send("{ENTER}") ;Start Telnet Application and open connection to Nortel Run("C:\WINDOWS\system32\telnet.exe") WinWaitActive("C:\WINDOWS\system32\telnet.exe") Send("open 198.206.164.1 3023") Send("{ENTER}") ;Enter Username\Password WinWaitActive("Telnet xxx.xxx.164.1") Send(GUICtrlRead($username)) Send("{ENTER}") WinWaitActive("Telnet xxx.xxx.164.1","",2) Send(GUICtrlRead($password)) Send("{ENTER}") ;Minimize telnet window WinSetState("Telnet xxx.xxx.164.1", "", @SW_MINIMIZE) ExitLoop Case $msg = $aboutitem Msgbox(0,"About","AutoConnect Version 1"& @CRLF &"written by: Cruz") Case $msg = $contactitem MsgBox(0,"Contact","For help email Cruz"& @CRLF &"cruz@myemailaddress.com") EndSelectWEndGUIDelete()Exit Link to comment Share on other sites More sharing options... Moderators SmOke_N Posted September 8, 2005 SmOke_N Moderators 16.3k 49 It's not what you know ... It's what you can prove! Moderators Share Posted September 8, 2005 You could create an .ini file to do this. IniWrite() your username and IniRead() on start up for the variable. Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options... AutoChris Posted September 8, 2005 AutoChris Active Members 367 Scripting with AutoIt since 2003 Share Posted September 8, 2005 Suggestion: Instead of leaving the username and password in a variable, put it in a text file temporarily. For example, I wrote a similar script (using one password for two apps) and just dropped the password into a text file, but I converted it into hexidecimal and scrambled the hex as well. Then when the script opened up for the other program, it unscrambled the hex and then converted it back into ASCII. Then you can just delete the dropped file. That way if someone were to somehow find the file, it would be VERY difficult to figure out the password unless they were privy to your code and the process you used to scramble/unscramble it. Link to comment Share on other sites More sharing options... Cruz Posted September 8, 2005 Cruz Members 7 Author Share Posted September 8, 2005 You could create an .ini file to do this. IniWrite() your username and IniRead() on start up for the variable.<{POST_SNAPBACK}>How would I capture the user entry for $username and send it to a file using IniWrite() then use IniRead () to put the username saved in the .ini file into the username input box?Sorry if I sound green but I am really new to this. Link to comment Share on other sites More sharing options... Moderators SmOke_N Posted September 8, 2005 SmOke_N Moderators 16.3k 49 It's not what you know ... It's what you can prove! Moderators Share Posted September 8, 2005 Create an .ini called MyIni on your desktop (instructions in the help file I believe). Setup ini like this for my example: [userProfile] UserName= PassWord= Then try this (Moved your GuiSetState() also (didn't pay much attention to the rest)) #include <GUIConstants.au3> ;Create GUI Window GUICreate("AutoConnect version 1.0",250,170) ;Create Help Menu $helpmenu = GuiCtrlCreateMenu ("&Help") $aboutitem = GuiCtrlCreateMenuitem ("&About",$helpmenu) $contactitem = GUICtrlCreateMenuitem ("&Contact",$helpmenu) ;Create Buttons $loginbutton = GuiCtrlCreateButton ("Login",30,110,70,20, $BS_DEFPUSHBUTTON) $cancelbutton = GuiCtrlCreateButton ("Cancel",150,110,70,20) $ReadName = IniRead(@DeskTopDir & "UserProfile", "UserName", "NF") $ReadPassWord = IniRead(@DeskTopDir & "UserProfile", "PassWord", "NF") ; INPUT Username & create username variable GUICtrlCreateLabel("Username:",20,32,70) $username = GUICtrlCreateInput($ReadName,80,30,150,20) GUICtrlSetState(-1,$GUI_ACCEPTFILES) ; INPUT Password & create password variable GUICtrlCreateLabel("Password:",20,62,70) $password = GUICtrlCreateInput($ReadPassWord,80,60,150,20,$ES_PASSWORD) GUICtrlSetState(-1,$GUI_ACCEPTFILES) GuiSetState() While 1 $msg = GUIGetMsg() Select Case $msg = $GUI_EVENT_CLOSE Or $msg = $cancelbutton ExitLoop Case $msg = $loginbutton $PutName = GUICtrlRead($username) $PutPassword = GUICtrlRead($password) IniWrite(@DeskTopDir & "UserProfile", "UserName", $PutName) IniWrite(@DeskTopDir & "UserProfile", "UserName", $PutName) ;Start Nortel VPN Client Run("C:\Program Files\Nortel Networks\Extranet.exe") WinWaitActive("Contivity VPN Client") ControlCommand("Contivity VPN Client","","ComboBox1","SelectString", 'United States, Richardson 1') ControlClick("Contivity VPN Client","",1000) Send("{TAB}") Send(GUICtrlRead($password)) Send("{ENTER}") WinWaitActive("Security Banner") Send("{ENTER}") ;Start Telnet Application and open connection to Nortel Run("C:\WINDOWS\system32\telnet.exe") WinWaitActive("C:\WINDOWS\system32\telnet.exe") Send("open 198.206.164.1 3023") Send("{ENTER}") ;Enter Username\Password WinWaitActive("Telnet xxx.xxx.164.1") Send(GUICtrlRead($username)) Send("{ENTER}") WinWaitActive("Telnet xxx.xxx.164.1","",2) Send(GUICtrlRead($password)) Send("{ENTER}") ;Minimize telnet window WinSetState("Telnet xxx.xxx.164.1", "", @SW_MINIMIZE) ExitLoop Case $msg = $aboutitem Msgbox(0,"About","AutoConnect Version 1"& @CRLF &"written by: Cruz") Case $msg = $contactitem MsgBox(0,"Contact","For help email Cruz"& @CRLF &"cruz@myemailaddress.com") EndSelect WEnd GUIDelete() Exit Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
Cruz Posted September 8, 2005 Author Share Posted September 8, 2005 Suggestion:Instead of leaving the username and password in a variable, put it in a text file temporarily. For example, I wrote a similar script (using one password for two apps) and just dropped the password into a text file, but I converted it into hexidecimal and scrambled the hex as well. Then when the script opened up for the other program, it unscrambled the hex and then converted it back into ASCII. Then you can just delete the dropped file.That way if someone were to somehow find the file, it would be VERY difficult to figure out the password unless they were privy to your code and the process you used to scramble/unscramble it.<{POST_SNAPBACK}>Thanks for your suggestion SerialKiller, but I don't want to capture or store the password just the username. I want the username to remain in the input box until it is changed then it should catpure the new input and place it in the input box the next time the script is run. Maybe I could use the scipt you wrote to do the same with username info. Can I see the scipt you wrote? Link to comment Share on other sites More sharing options...
Cruz Posted September 8, 2005 Author Share Posted September 8, 2005 Thanks Ron, you rule! I was able to use your code to store the username in the myini.ini file. Any ideas on how to send the telnet window to the systray? Thanks again. Link to comment Share on other sites More sharing options...
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