 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
JonTheNiceGuy
Joined: 22 Apr 2004 Posts: 18 Location: Manchester, UK
|
Posted: Mon Apr 26, 2004 6:37 pm Post subject: Reading Configuration Files... |
|
|
I'm trying to write a configuration script reader, and I'm not having a lot of luck making it work.
Here's what I've got...
| Code: | Loop, read, config.ini
{
Loop, parse, A_LoopReadLine, =
{
msgbox,%a_index% has a value of %A_LoopField%
if %a_index%<2
{
Variable = ; No Variable Set
Command = %A_LoopField%
}
If %a_index%>1
{
Variable = %A_LoopField%
if %Command% = Password
{
Username = %Variable%
}
if %Command% = Password
{
Password_old = %Password%
Password = %Password_old%{ASC %Variable%}
}
if %Command% = Server
{
Server = %Variable%
gosub,LaunchServer
}
}
Msgbox,Loop
}
}
exit
LaunchServer:
MsgBox,User %Username% with a password of %Password% Will access %Server%
Return |
And here's the config file...
| Code: | Username=jon.the.nice.guy
Password=65
Password=66
Password=32
Password=69
Password=54
Server=DC01
Server=DC02
Server=DC03
Server=TS01
Server=TS03
Server=FP01 |
|
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10464
|
Posted: Mon Apr 26, 2004 9:06 pm Post subject: |
|
|
It's probably best to change the layout of your file to be more line-centric, perhaps something like this:
Username,jon.the.nice.guy
Server,DC01,65
Server,DC02,66
| Code: | Loop, read, config.ini
{
StringSplit, field, A_LoopReadLine, `,
if field1 = Username
Username = %field2%
else if field1 = Server
{
Server = %field2%
Password = %field3%
}
if Username <>
if Server <>
if Password <>
Gosub, LaunchServer
}
Exit
LaunchServer:
MsgBox,User %Username% with a password of %Password% Will access %Server%
Return
|
The above will probably need some adjustment for your exact purpose. You could also use the built-in IniRead and IniWrite functions if you'd prefer to use the standard INI format, which might be easier depending on the scope of what you're doing. |
|
| Back to top |
|
 |
beardboy
Joined: 02 Mar 2004 Posts: 444 Location: SLC, Utah
|
Posted: Mon Apr 26, 2004 9:17 pm Post subject: |
|
|
If you want to continue using INI file you could also change the format to be something like this.
| Code: | [Default]
Username=jon.the.nice.guy
[Server1]
Name=DC01
Password=65
[Server2]
Name=DC02
Password=66
[Server3]
Name=DC03
Password=32
[Server4]
Name=TS01
Username=test.user
Password=69 |
You can then do a loop to change the [ServerX] number using something like this:
| Code: | inifile = config.ini
Loop
{
IniRead, name, %inifile%, Server%A_Index%, Name
if name = ERROR ; Check to see if ServerX even exists
{
break ; Terminate Loop
}
IniRead, username, %inifile%, Server%A_Index%, Username
if username = ERROR ; Check to see if username exists
{
IniRead, username, %inifile%, Default, Username
}
IniRead, password, %inifile%, Server%A_Index%, Password
MsgBox, 0, Testing, Server = %name%`nUsername = %username%`nPassword = %password%
} |
|
|
| Back to top |
|
 |
JonTheNiceGuy
Joined: 22 Apr 2004 Posts: 18 Location: Manchester, UK
|
Posted: Mon Apr 26, 2004 11:07 pm Post subject: |
|
|
I was actually going to build the password into a series of ascii characters it would send - giving me a little bit of security... so I'd loop as follows:
| Code: | password_old = %password%
password = %password{ASC %value%} |
Then I can send %password%
But, I'll play with this for now, and if I can't make it work, I'll come back  |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|