executing function for each username/password Topic is solved

Get help with using AutoHotkey (v2 or newer) and its commands and hotkeys
jaccotjuhhh
Posts: 27
Joined: 16 Mar 2018, 08:45

executing function for each username/password

28 Apr 2024, 16:24

yes hello and hi
i have big code thats doing exactly what i want.
but now i have to do this for multiple accounts.
i have an INI file containing settings.
this script is one i use privately so i have no need for making it hack-proof.

lets say for this example i have this part of my INI file:

Code: Select all

[credentials1]
username=john
password=123
[credentials2]
username=joe
password=321
[credentials3]
username=jan
password=1234
how can i achieve something that i would sketch as:

Code: Select all

inipath := A_WorkingDir "\data\config.ini"
inifile := Fileread(inipath)
for username in inifile{
funtion1(username, password)
}
so in english: how can i execute function1 for multiple username/passwords?
User avatar
mikeyww
Posts: 27139
Joined: 09 Sep 2014, 18:38

Re: executing function for each username/password  Topic is solved

28 Apr 2024, 16:53

Hello,

Use :arrow: IniRead to read your INI file.

Code: Select all

#Requires AutoHotkey v2.0
ini           := 'config.ini'
sectionNames  := IniRead(ini)
For section in StrSplit(sectionNames, '`n') {
 user := IniRead(ini, section, 'username')
 pwd  := IniRead(ini, section, 'password')
 f(user, pwd)
}

f(user, pwd) {
 MsgBox 'User       :  ' user '`nPassword: ' pwd, 'Information'
}
jaccotjuhhh
Posts: 27
Joined: 16 Mar 2018, 08:45

Re: executing function for each username/password

29 Apr 2024, 09:40

@mikeyww hi MikeyWW Thanks so much!
How would you approach if the INI file also contains other unrelated sections?
I'm having trouble applying a correct strsplit for that..
My route would be to

Code: Select all

try
each section but im not sure if that's a good route.
User avatar
mikeyww
Posts: 27139
Joined: 09 Sep 2014, 18:38

Re: executing function for each username/password

29 Apr 2024, 09:52

That is OK if it works. I also recommend reading the documentation section pertaining to the "Default" parameter.

Return to “Ask for Help (v2)”

Who is online

Users browsing this forum: wysnxzm and 39 guests