Sign in to follow this  
Followers 0
Overkill

Newbie needs help!

13 posts in this topic

#1 ·  Posted (edited)

I am creating an autologin script that will be somewhat user-friendly, and I want to save the credentials and other variables in an INI file so that a few things can happen:

*) User is able to change INI file to make the script suit his/her needs without decompiling script

1) Script can read settings from the INI file for multiple websites, so that a user can select the site from a dropdown menu and log in

2) Script loads the settings when site is selected and displays them in editable input controls

3) If the variable is changed within the above controls, the script saves any changes to the INI file

4) When user clicks a button, login is processed

--> I can get #4 done easily, but #s 1-3 I need help with

Can someone point me in the right direction? I'm having trouble finding useful literature.

If this is too much work, the bare minimum here is reading vars from INI file.

Thanks guys!

AutoIt is awesome :)

Edited by Overkill

Share this post


Link to post
Share on other sites



I am creating an autologin script that will be somewhat user-friendly, and I want to save the credentials and other variables in an INI file so that a few things can happen:

*) User is able to change INI file to make the script suit his/her needs without decompiling script

1) Script can read settings from the INI file for multiple websites, so that a user can select the site from a dropdown menu and log in

2) Script loads the settings when site is selected and displays them in editable input controls

3) If the variable is changed within the above controls, the script saves any changes to the INI file

4) When user clicks a button, login is processed

--> I can get #4 done easily, but #s 1-3 I need help with

Can someone point me in the right direction? I'm having trouble finding useful literature.

If this is too much work, the bare minimum here is reading vars from INI file.

Thanks guys!

AutoIt is awesome :)

Answers:

1) INIRead,

2) ie.au3 (UDF Library)

3) INIWrite

They're the functions (or in the case of ie.au3, UDF library) that should get you started. Welcome to the forums too :D

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Bert covered it, but I would add that if you want variable numbers of things to show up, use an array variable to hold the entries.

One command can read an INI section to the array, the array is easy to walk through without knowing ahead of time how long it is, and one command can write the array back to an INI section after any editing.

So see also in the help file: IniReadSection() and IniWriteSection().

Quickie demo:

Here's the Test.ini file:

[OtherStuff]
a = 1
b = 2

[URLs]
1 = http://www.autoitscript.com
2 = http://www.openoffice.org
3 = http://www.mozilla.com/firefox

[SomeMoreStuff]
1 = a
2 = b

Here's a demo script to use it. Note that you can add more URLs in the ini file and the GUI will self adjust:

#include <guiconstants.au3>

Opt("GuiOnEventMode", 1)

; Read ini file [URLs] section
$IniFile = @ScriptDir & "\Test.ini"
$avIniSec = IniReadSection($IniFile, "URLs")
If @error Then
    MsgBox(16, "Error!", "Error reading ini file [URLs] section: " & $IniFile)
    Exit
ElseIf $avIniSec[0][0] = 0 Then
    MsgBox(16, "Error!", "[URLs] section contains no entries")
    Exit
EndIf

; Create GUI, height is determined by number of URLs
$hGUI = GUICreate("INI Test", 400, 50 + (40 * $avIniSec[0][0]))
GUISetOnEvent($GUI_EVENT_CLOSE, "_Quit")
GUICtrlCreateLabel("Demo: Reading URLs from INI file", 10, 10, 380, 30, $SS_CENTER)
GUICtrlSetFont(-1, 16, 600)

; Add buttons to GUI
For $n = 1 To $avIniSec[0][0]
    GUICtrlCreateButton($avIniSec[$n][0] & ": " & $avIniSec[$n][1], 20, 10 + ($n * 40), 360, 30)
    GUICtrlSetOnEvent(-1, "_ButtonHit")
Next
GUISetState()

; Idle loop while GUI is up
While 1
    Sleep(20)
WEnd


; Function to handle button clicks
Func _ButtonHit()
    MsgBox(64, "Button Hit!", "You clicked on:  " & GUICtrlRead(@GUI_CtrlId))
EndFunc   ;==>_ButtonHit

; Function to exit script
Func _Quit()
    Exit
EndFunc   ;==>_Quit

:)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Holy hamburgers!

Posted Image

Thanks Psalty...that's pretty much my script right there. Now, all I need to do is tweak the GUI and write the logon scripts. YAY!

Now...quick question:

How do you read the array? Does each [] represent a column in a matrix, and $n is the row?

I'm not using anything more than a 2-D array but if I get into the whole programming thing, I might need to know all about them since it looks like they're useful.

Does anybody have a URL for a guide that I can read that explains the concept behind an array, rather than "to do [task] use [process]" approach? I like to know WHY I'm doing something before I do it...that way I have a full grasp of the applications it has.

Thanks,

Overkill

Edited by Overkill

Share this post


Link to post
Share on other sites

Thanks Psalty...

You're welcome too. :D

Now...quick question:

How do you read the array? Does each [] represent a column in a matrix, and $n is the row?

I'm not using anything more than a 2-D array but if I get into the whole programming thing, I might need to know all about them since it looks like they're useful.

Arrays are extremely useful, and once you learn them in any one language you can apply it just about any other. (I've even used them in DOS .bat files - It can be done!)

Read the help file on Dim/ReDim/Global/Local and the general section on variables.

A 1D array is just a list, with only one subscript (the number in the box). Then only tricky part is that the first one is zero:

Dim $avFruits[3] = ["apple", "blueberry", "cherry"]oÝ÷ ØÚ-Ç­«mæ«­¬¢±×ªÞw­w¥zg§¶Æî¶Ø^ɪÞéz·ÒØk»`6
ªëk(¬ë-0ýÊ%ºiíi¹^jwgyçl·
,¹»®*m±«­¢+ØÀÌØíÙ9ÕµÉÍlÉulÕoÝ÷ Ú«¨µàèzƧɺʯy¥-ú+j¢uëajÒjzÞiÛaj×±¦V¢ËayÊ'qêmmèbÖ§jºÚʶ­êí©êºm¡Ú-jÉ.±êk¡Ç¬²«¨µªi®bëhz0XvßÙ¢)ಶ§·¢·v­¶­Á¬«Þiû¥
Ú²¶¦bq«b¢{"¶¬þ«¨µäáz·0zºjºÚÊÇ(ë®­áh¯ó^ÆÙh¢¢Ç­ç¥zg§¶Æ«y©ei×kzËv{¦z¸jYrÊj|+׬í)²ØZ·¥Øk¢è!jv«­¬¢Ë^iÚ¸­x-ëæÚ²'¡×¨½êÚÚ/z¶ j)Ó«wöÌ!jÛaÊZ®Ú¶zj0zY]zj,jëh×6For $n = 1 To $avIniSec[0][0]
    GUICtrlCreateButton($avIniSec[$n][0] & ": " & $avIniSec[$n][1], 20, 10 + ($n * 40), 360, 30)
    GUICtrlSetOnEvent(-1, "_ButtonHit")
Next

That loop could create 40 buttons as easily two, with no additional code.

You've been a good class. Time for recess! :)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

I'm having trouble getting this:

For $n = 1 To $avIniSec[0][0]

What exactly happens here?

Share this post


Link to post
Share on other sites

I'm having trouble getting this:

For $n = 1 To $avIniSec[0][0]

What exactly happens here?

All arrays in AutoIt are zero-based. The first element is alway element zero. Many functions (but not all) like IniReadSection() return their data in an array with the first element sent to the total count of data elements. Since the demo script's ini file had three URLs in the section, IniReadSection() returned a four element array (really four-by-two, since it's a 2D array). The first element contains the count (3, in this case) and then elements 1 thru 3 contain the data.

From the demo, the contents look like this:

$avIniSec[0][0] = 3 ; Count, set by the function
$avIniSec[0][1] = "" ; Not used

$avIniSec[1][0] = "1"
$avIniSec[1][1] = "http://www.autoitscript.com"
$avIniSec[2][0] = "2"
$avIniSec[2][1] = "http://www.openoffice.org"
$avIniSec[3][0] = "3"
$avIniSec[3][1] = "http://www.mozilla.com/firefox"

The For/Next loop uses the returned count in $avIniSec[0][0] to control how many times to run the loop. In the demo, the loop runs three times with values for $n of 1 to 3.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

ok...i get it. I thought that the array started at 0,0 with 1, then 0,1 with the first url. I get it!

Thanks psalty! I love you!

Will you e-marry me? :)

Seriously though, thanks for all the help.

Now, each URL is going to have its own logon script. the function "_buttonhit" does the same thing for every press. What should I do to [still editing]

Edited by Overkill

Share this post


Link to post
Share on other sites

Ok...since it won't let me edit my post I am going to simply add another reply.

Now, each URL is going to have its own logon script. I'm thinking about doing something like this...and yes there are still a few more questions afterward.

In the INI:

[URLs]
1 = eBay

[ebay]
tosite = "!dhttps://signin.ebay.com/ws/eBayISAPI.dll?SignIn{ENTER}"
waittime = 500
touser = {tab}
username = myusername
topass = {tab}
password = mypassword
tologin = "{TAB}{TAB}{SPACE}{SHIFTDOWN}{TAB}{SHIFTUP}{ENTER}"

The buttonhit function:

Func _ButtonHit()

$site = GUICtrlRead(@GUI_CtrlId)
$avIniLogin = IniReadSection($IniFile, $site)

Run($browser)         ; declared & defined in beginning of the script somewhere
Send("" & $tosite)
Sleep($waittime)
Send("" & $touser)
Send("" & $username)
Send("" & $topassword)
Send("" & $tologin)

EndFunc

Now...I know it can't be that simple. Can I define variables in the INI like that? What changes, if any, do I need to make?

Share this post


Link to post
Share on other sites

That looks like a workable path to me. :)

Yes, you can pass variables as parameters to functions; a vital thing to most scripts. Just FYI, you can even have the returned value of one function be the input parameter to another function, just like nesting math operations in sets of parentheses.

This will read the file and section names from a gui's input controls:

IniReadSection(GuiCtrlRead($Input1), GuiCtrlRead($Input2))

You haven't shown how you get the section data from the array into the individual variables (i.e. $tosite, $touser). There is a choice to make there: either use the array references directly, or read the data out of the array into some variables first.

Keep at it!

:D


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Hmm...I'm going to work on the GUI. I think I've got the rest of it pretty well covered. I've got about 20 hours of train ride to play with all this in the next 2 days. Sleep + Code + Disturbed, Godsmack, Chumbawamba, Dragonforce, Metallica, Rob/White Zombie = Fun!

Share this post


Link to post
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
Sign in to follow this  
Followers 0