Sign in to follow this  
Followers 0
Mouse1989

AutoIt #include

19 posts in this topic

#1 ·  Posted (edited)

I was recently trying to do another script where the main script uses variables from a .txt file.

#include <config.txt>

where the config file has 2 variables quoting the username and password.

I got it all working but found after I had compiled the script and then changed the .txt file information the compiled script didn't register the changes and still used the information as if I had forgot to save the new changes in the .txt.

Any ideas around this?

Edited by Mouse1989

Share this post


Link to post
Share on other sites



why dont save these informations in an ini file then use IniRead to get they

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Because Im still kinda new at AutoIt scripting., so I don't know many of the workarounds yet xD

But thanks, I'll give it a go.

What should the .ini look like?

I read the help file but am at a lost cause. I have:

[section1]
log="username"
[section2]
pss="pass"

Then in my script I have:

$o_Usrnm = IniRead("\config.ini", "section1", "log", "NotFound")
$o_Pswd = IniRead("\config.ini", "section2", "pss", "NotFound")
Edited by Mouse1989

Share this post


Link to post
Share on other sites

I was recently trying to do another script where the main script uses variables from a .txt file.

#include <config.txt>

where the config file has 2 variables quoting the username and password.

I got it all working but found after I had compiled the script and then changed the .txt file information the compiled script didn't register the changes and still used the information as if I had forgot to save the new changes in the .txt.

Any ideas around this?

I think you misunderstand what an #include file does for you. It includes it's content into the script code. Global variable definitions and function declarations are all that should really be in there. Text like "password=MyPassWord" would be invalid as a line in your script and is therefore invalid as a line in an #include file. You could declare a variable (same as if it was in your script) with:
Global $sPassword = "MyPassWord"

The problem there is that gets read in only when you compile the script (or run it uncompiled from the command line or SciTE). Changing the contents after compiling with the included file doesn't change what's already been put in the compiled .exe file. The file is not read again after compiling.

Your use of an .ini should work -- keeping in mind that putting username/password data in any file, including an AutoIt script is a BAD idea -- because the file gets read each time and changes will get used.

:)


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

Thanks for you reply. Any idea where I'm going wrong on my .ini script though?

Share this post


Link to post
Share on other sites

Thanks for you reply. Any idea where I'm going wrong on my .ini script though?

What happens when you run it, and are you sure the path to the .ini file works as "\config.ini"?

:)


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

#7 ·  Posted (edited)

I changed the path name and rechecked all the names and spelling but I still get NotFound in both username and password on the website.

script.au3

$o_Usrnm = IniRead("C:\Documents and Settings\Admin\Desktop\script\config.ini", "username", "Name", "NotFound")
    $o_Pswd = IniRead("C:\Documents and Settings\Admin\Desktop\script\config.ini", "password", "Pass", "NotFound")

config.ini

[username]
Name=username
[password]
Pass=pass
Edited by Mouse1989

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

I changed the path name and rechecked all the names and spelling but I still get NotFound in both username and password on the website.

script.au3

$o_Usrnm = IniRead("C:\Documents and Settings\Admin\Desktop\script\config.ini", "username", "Name", "NotFound")
    $o_Pswd = IniRead("C:\Documents and Settings\Admin\Desktop\script\config.ini", "password", "Pass", "NotFound")

config.ini

[username]
Name=username
[password]
Pass=pass
I don't see the problem. Still seems like you must not be seeing the .ini file.

Try it this way:

$sIniFile = "C:\Documents and Settings\Admin\Desktop\script\config.ini"
If FileExists($sIniFile) Then
    $o_Usrnm = IniRead($sIniFile, "username", "Name", "NotFound")
    $o_Pswd = IniRead($sIniFile, "password", "Pass", "NotFound")
    MsgBox(64, "Results", "$o_Usrnm = " & $o_Usrnm & "  $o_Pswd = " & $o_Pswd)
Else
    MsgBox(16, "Error", "Ini file not found: " & $sIniFile)
EndIf

:)

Edit: Replaced missing "Then" after IF condition.

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

Heh still no luck >.< lol

Share this post


Link to post
Share on other sites

Heh still no luck >.< lol

Try, the message I am getting running PsaltyDS suggestion code is:

"NotFound" ...

or

"Ini file not found"...

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

I did try that but I didn't get a message box =/ lol

perhaps if I post my whole code up to what I have at the moment.

;open a IE page and navigate to game
    #include <IE.au3>
    $o_IE = _IEcreate("http://www.site.com")
;wait until page has loaded
    _IELoadWait ($o_IE)
    Dim $_Usrnm, $_Pswd
    $o_Usrnm = IniRead ("C:\Documents and Settings\Admin\Desktop\script\config.ini", "Details", "Name","not  found")
    $o_Pswd = IniRead("C:\Documents and Settings\Admin\Desktop\script\config.ini", "Details", "Pass", "Not Found")


$y=2
Do
    sleep(2000)
;gets form
    $o_Form = _IEFormGetObjByName ($o_IE, "memberloginForm")
;enters username into field
    $o_Usr = _IEFormElementGetObjByName ($o_Form, "username")
    _IEFormElementSetValue($o_Usr, $o_Usrnm)
    sleep(1000)
;enters password into field
    $o_Psw = _IEFormElementGetObjByName ($o_Form, "password")
    _IEFormElementSetValue($o_Psw, $o_Pswd)
;waits 2 seconds and then logs in
    sleep(2000)
    _IEFormSubmit ($o_Form)

config.ini

[Details]

Name = name
Pass = pass

I posted config.ini again because I changed it to make the names more formal

Edited by Mouse1989

Share this post


Link to post
Share on other sites

I did try that but I didn't get a message box =/ lol

perhaps if I post my whole code up to what I have at the moment.

;open a IE page and navigate to game
    #include <IE.au3>
    $o_IE = _IEcreate("http://www.site.com")
;wait until page has loaded
    _IELoadWait ($o_IE)
    Dim $_Usrnm, $_Pswd
    $o_Usrnm = IniRead ("C:\Documents and Settings\Admin\Desktop\script\config.ini", "Details", "Name","not  found")
    $o_Pswd = IniRead("C:\Documents and Settings\Admin\Desktop\script\config.ini", "Details", "Pass", "Not Found")

$y=2
Do
    sleep(2000)
;gets form
    $o_Form = _IEFormGetObjByName ($o_IE, "memberloginForm")
;enters username into field
    $o_Usr = _IEFormElementGetObjByName ($o_Form, "username")
    _IEFormElementSetValue($o_Usr, $o_Usrnm)
    sleep(1000)
;enters password into field
    $o_Psw = _IEFormElementGetObjByName ($o_Form, "password")
    _IEFormElementSetValue($o_Psw, $o_Pswd)
;waits 2 seconds and then logs in
    sleep(2000)
    _IEFormSubmit ($o_Form)

config.ini

[Details]

Name = name
Pass = pass

I posted config.ini again because I changed it to make the names more formal

Assuming you inserted the code I gave you into that (which you do not indicate), then how do you know the script ever continued after _IELoadWait()? It is common for that to hang if the page being loaded pops a security dialog. Dealing with that has bee covered many times (using $f_wait = 0 and avoiding _IELoadWait).

:)


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

#13 ·  Posted (edited)

Ok I just tried you're script and got the results of

$o_Usrnm = NotFound

$o_Pswd = NotFound

So Im guessing it can find the ini file but not the username/pass.

As it didn't havea msgbox saying Ini file not found.

So my ini is laid out wrong?

Edited by Mouse1989

Share this post


Link to post
Share on other sites

Ok I just tried you're script and got the results of

$o_Usrnm = NotFound

$o_Pswd = NotFound

So Im guessing it cant find it then?

Divide your "problem" into 2 parts:

1. Reading INI file (config.ini)

2. Getting Data from IE Webpage/Form.

Once you have both working independently, then try combining them.

Share this post


Link to post
Share on other sites

Ok I just tried you're script and got the results of

$o_Usrnm = NotFound

$o_Pswd = NotFound

So Im guessing it can find the ini file but not the username/pass.

As it didn't havea msgbox saying Ini file not found.

So my ini is laid out wrong?

Did you get the "Results" MsgBox with those values or are reading the returned value some other way? (You still haven't posted the code snippet you actually ran.)

:)


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

#16 ·  Posted (edited)

Thanks for your input DaRam

But finally I have sorted it. I worked around the problem with this.

IniWrite ("confi.ini", "username", "user", "myusername")
IniWrite ("confi.ini", "password", "pass", "mypass")

That gave me the correct .ini layout

[username]
user=myusername
[password]
pass=mypass

I then just replaced the section and the key names xD and it worked. Woohoo

Thanks for your help both of you, sorry if I used up too much of your evening.

Edited by Mouse1989

Share this post


Link to post
Share on other sites

Thanks for your input DaRam

But finally I have sorted it. I worked around the problem with this.

IniWrite ("confi.ini", "username", "user", "myusername")
IniWrite ("confi.ini", "password", "pass", "mypass")

That gave me the correct .ini layout

[username]
user=myusername
[password]
pass=mypass

I then just replaced the section and the key names xD and it worked. Woohoo

Thanks for your help both of you, sorry if I used up too much of your evening.

It still bothers me that you couldn't read the values from the original .ini file. How had it been written? Any chance it was Unicode vice ANSI before you wrote it with IniWrite()?

:)


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

It still bothers me that you couldn't read the values from the original .ini file. How had it been written? Any chance it was Unicode vice ANSI before you wrote it with IniWrite()?

:)

And, also that you wrote to confi.ini and read back it worked.

Your original code was to config.ini

$o_Usrnm = IniRead ("C:\Documents and Settings\Admin\Desktop\script\config.ini", "Details", "Name","not  found")

Share this post


Link to post
Share on other sites

Yh lol that was just because I was testing it. I changed the file names of the /ini back when I tried it properly.

and Im not sure, I followed the standard .ini from the AutoIt help file, but it didn't work xD lesson learned I guess.

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