Jump to content

Read from Ini for varible?


Shyke
 Share

Recommended Posts

Here is my code:

$User = IniRead($Ini, "Configuration", "UserName", "NotFound")

How can I get it so that $User is set to the key that is to be read from $Ini from the section "Configuration" and the name "UserName"?

Link to comment
Share on other sites

or maybe this.... where your $User="UserName" ( from your post )

$var = IniReadSection("User.ini", "Configuration")
If @error Then 
    MsgBox(4096, "", "Error occured, probably no INI file.")
Else
    For $i = 1 To $var[0][0]
        MsgBox(4096, "", "Key: " & $var[$i][0] & @CRLF & "Value: " & $var[$i][1])
    Next
EndIf

8)

NEWHeader1.png

Link to comment
Share on other sites

Maybe I should give you more code:

$LoginL = GUICtrlCreateGroup("Login", 10, 10, 220, 105)

$UsernameL = GUICtrlCreateLabel("Username:", 20, 25, 50, 20)

$Username = GUICtrlCreateInput("Username", 80, 25, 140, 20)

$PasswordL = GUICtrlCreateLabel("Password:", 20, 45, 50, 20)

$Password = GUICtrlCreateInput("Password", 80, 45, 140, 20, $ES_PASSWORD)

$CharacterL = GUICtrlCreateLabel("Character:", 20, 65, 120, 20)

$Character = GUICtrlCreateInput("1", 150, 65, 70, 20)

$Login = GUICtrlCreateButton("Login", 90, 85, 60, 20)

DirRemove($Path & "WDB", 1)

GUISetState()

While 1

$msg = GUIGetMsg()

Select

; Login

Case $msg = $Login

$User = IniRead($Ini, "Configuration", "UserName", "NotFound")

$Pass = IniRead($Ini, "Configuration", "Password", "NotFound")

$Char = IniRead($Ini, "Configuration", "Character", "NotFound")

GUICtrlSetData($Username, $User)

GUICtrlSetData($Username, $Pass)

GUICtrlSetData($Username, $Char)

That should give you all the info needed, how can I make it so that there is like a "remember" feature like I was explaining?

Link to comment
Share on other sites

if i understand you scriptlet above correctly... you are asking for a user name with this

$Username = GUICtrlCreateInput("Username", 80, 25, 140, 20)

then when they press the "login" button. you are reading the $User from the ini with this

$User = IniRead($Ini, "Configuration", "UserName", "NotFound")

thenm you are replacing what the user typed in as their $Username with your ini read of $User with this

GUICtrlSetData($Username, $User)

thus... the information put in the $username in the GUI is lost

maybe you want to iniwrite ?????

8)

NEWHeader1.png

Link to comment
Share on other sites

I will just put the whole script here... I really didn't want to though...

#include <GuiConstants.au3>
; Order = left|up|width|height
$Path = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Blizzard Entertainment\World of Warcraft\", "InstallPath")
$WoW = $Path & "WoW.exe"
$Ini = $Path & "login.ini"

;If Not IsDeclared('WS_CLIPSIBLINGS') Then Global $WS_CLIPSIBLINGS = 0x04000000

GUICreate("WoW Auto Login", 240, 125, (@DesktopWidth - 240) / 2, (@DesktopHeight - 125) / 2, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)

$LoginL = GUICtrlCreateGroup("Login", 10, 10, 220, 105)
$UsernameL = GUICtrlCreateLabel("Username:", 20, 25, 50, 20)
$Username = GUICtrlCreateInput("Username", 80, 25, 140, 20)
$PasswordL = GUICtrlCreateLabel("Password:", 20, 45, 50, 20)
$Password = GUICtrlCreateInput("Password", 80, 45, 140, 20, $ES_PASSWORD)
$CharacterL = GUICtrlCreateLabel("Character Number (1-10):", 20, 65, 120, 20)
$Character = GUICtrlCreateInput("1", 150, 65, 70, 20)
$Login = GUICtrlCreateButton("Login", 90, 85, 60, 20)

DirRemove($Path & "WDB", 1)

GUISetState()
While 1
    $msg = GUIGetMsg()
    Select
    ; Login
        Case $msg = $Login
                $User = IniRead($Ini, "Configuration", "UserName", "NotFound")
                $Pass = IniRead($Ini, "Configuration", "Password", "NotFound")
                $Char = IniRead($Ini, "Configuration", "Character", "NotFound")
                GUICtrlSetData($Username, $User)
                GUICtrlSetData($Username, $Pass)
                GUICtrlSetData($Username, $Char)
                FileDelete($Ini)
                IniWrite($Ini, "Configuration", "UserName", $Username)
                IniWrite($Ini, "Configuration", "Password", $Password)
                IniWrite($Ini, "Configuration", "WoW", $WoW)
                IniWrite($Ini, "Configuration", "Character", $Character)
                IniWrite($Ini, "Configuration", "Title", "World of Warcraft")
                IniWrite($Ini, "Configuration", "Delay", "13000")
                IniWrite($Ini, "Configuration", "Delay2", "6000")
            Else
                IniWrite($Ini, "Configuration", "UserName", $Username)
                IniWrite($Ini, "Configuration", "Password", $Password)
                IniWrite($Ini, "Configuration", "WoW", $WoW)
                IniWrite($Ini, "Configuration", "Character", $Character)
                IniWrite($Ini, "Configuration", "Title", "World of Warcraft")
                IniWrite($Ini, "Configuration", "Delay", "13000")
                IniWrite($Ini, "Configuration", "Delay2", "6000")
            EndIf
            
            $Character = IniRead($Ini, "Configuration", "Character", "NotFound")
            If $Character > 10 Or $Character < 0 Then
                MsgBox(48, "WoW Auto Login", "Error!" & @CRLF & "You have typed a character number that is out of bounds." & @CRLF & "Click OK to continue.")
                Exit
            EndIf
            
            $Title = IniRead($Ini, "Configuration", "Title", "NotFound")
            
            If WinExists($Title) Then
                ProcessClose("WoW.exe")
                Sleep(5000)
                Run($WoW)
            Else
                Run($WoW)
            EndIf
            
            $Delay = IniRead($Ini, "Configuration", "Delay", "NotFound")
            $Delay2 = IniRead($Ini, "Configuration", "Delay2", "NotFound")
            
            Sleep($Delay)
            Send($Username)
            Send("{TAB}")
            Send($Password)
            Send("{ENTER}")
            Sleep($Delay2)
            
            $DW = @DesktopWidth
            $DH = @DesktopHeight
            If $DW = 800 And $DH = 600 Then
                MouseClick("left", 701, 84, 1, 10)
            Else
                If $DW = 1024 And $DH = 768 Then
                    MouseClick("left", 835, 110, 1, 10)
                Else
                    MsgBox(48, "WoW Auto Login", "Error!" & @CRLF & "Your desktop resolution isn't supported, please change your desktop resolution to either 800 x 600 or 1024 x 768." & @CRLF & "Click OK to continue.")
                    Exit
                EndIf
            EndIf
            
            Send("{DOWN " & $Character & "}")
            Sleep(1000)
            Send("{ENTER}")
            Exit
            
        Case $msg = $GUI_EVENT_CLOSE
            Exit
    EndSelect
WEnd
Link to comment
Share on other sites

i have lots of errors with your script

1

$Path = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Blizzard Entertainment\World of Warcraft\", "InstallPath")

then

DirRemove($Path & "WDB", 1)

****** the $path is not a Dir that can be removed

2

; Login

Case $msg = $Login

then

Else

IniWrite($Ini, "Configuration", "UserName", $Username)

******* the "Else" is for an "if" statement... not a "Case"

3

i dunno

8)

NEWHeader1.png

Link to comment
Share on other sites

ok

if i were writting this script.... i would

1

put a "save info" button on the gui

2

when the script is started it would look for ( and if found) read the ini and set the info into the gui

3

when they press login it just runs... no more ini stuff

8)

number 1 above

GUICreate("WoW Auto Login", 240, 125, (@DesktopWidth - 240) / 2, (@DesktopHeight - 125) / 2, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)

$LoginL = GUICtrlCreateGroup("Login", 10, 10, 220, 105)
$UsernameL = GUICtrlCreateLabel("Username:", 20, 25, 50, 20)
$Username = GUICtrlCreateInput("Username", 80, 25, 140, 20)
$PasswordL = GUICtrlCreateLabel("Password:", 20, 45, 50, 20)
$Password = GUICtrlCreateInput("Password", 80, 45, 140, 20, $ES_PASSWORD)
$CharacterL = GUICtrlCreateLabel("Character Number (1-10):", 20, 65, 120, 20)
$Character = GUICtrlCreateInput("1", 150, 65, 70, 20)
$Login = GUICtrlCreateButton("Login", 100, 87, 60, 20)
$SaveIni = GUICtrlCreateButton("Save Info", 30, 87, 60, 20)

DirRemove($Path & "WDB", 1)

GUISetState()
While 1

8)

NEWHeader1.png

Link to comment
Share on other sites

Number 2 Above

this

DirRemove($Path & "WDB", 1)
Ini_Reader(); ****** ad this line here
GUISetState()
While 1

and this at the very bottom of yopur script

;----------- Functions --------------------


Func Ini_Reader()
    If FileExists($Ini) Then
        $User = IniRead($Ini, "Configuration", "UserName", "NotFound")
        $Pass = IniRead($Ini, "Configuration", "Password", "NotFound")
        $Char = IniRead($Ini, "Configuration", "Character", "NotFound")
        GUICtrlSetData($Username, $User)
        GUICtrlSetData($Password, $Pass)
        GUICtrlSetData($Character, $Char)
    EndIf
EndFunc

8)

NEWHeader1.png

Link to comment
Share on other sites

something i "thought" i taught you before

keep it clean

GUISetState()
While 1
    $msg = GUIGetMsg()
    
    If $msg = $Login Then
    ; hide the gui ????
        Call("Run_Login")
    EndIf
    
    If $msg = $SaveIni Then
        Call("Save_Ini")
    EndIf
    
    If $msg = $GUI_EVENT_CLOSE Then Exit
    
WEnd

8)

NEWHeader1.png

Link to comment
Share on other sites

Alright, I fixed some stuff...

#include <GuiConstants.au3>
; Order = left|up|width|height
$Path = RegRead("HKEY_LOCAL_MACHINE\SOFTWARE\Blizzard Entertainment\World of Warcraft\", "InstallPath")
$WoW = $Path & "WoW.exe"
$Ini = $Path & "login.ini"

;If Not IsDeclared('WS_CLIPSIBLINGS') Then Global $WS_CLIPSIBLINGS = 0x04000000

GUICreate("WoW Auto Login", 240, 125, (@DesktopWidth - 240) / 2, (@DesktopHeight - 125) / 2, $WS_OVERLAPPEDWINDOW + $WS_VISIBLE + $WS_CLIPSIBLINGS)

$LoginL = GUICtrlCreateGroup("Login", 10, 10, 220, 105)
$UsernameL = GUICtrlCreateLabel("Username:", 20, 25, 50, 20)
$Username = GUICtrlCreateInput("Username", 80, 25, 140, 20)
$PasswordL = GUICtrlCreateLabel("Password:", 20, 45, 50, 20)
$Password = GUICtrlCreateInput("Password", 80, 45, 140, 20, $ES_PASSWORD)
$CharacterL = GUICtrlCreateLabel("Character Number (1-10):", 20, 65, 120, 20)
$Character = GUICtrlCreateInput("1", 150, 65, 70, 20)
$Login = GUICtrlCreateButton("Login", 80, 85, 60, 20)

DirRemove($Path & "WDB", 1)
Reader()
Writer()
Reader()
$Title = IniRead($Ini, "Configuration", "Title", "NotFound")
$Char = IniRead($Ini, "Configuration", "Character", "NotFound")
$Delay = IniRead($Ini, "Configuration", "Delay", "NotFound")
$Delay2 = IniRead($Ini, "Configuration", "Delay2", "NotFound")

GUISetState()
While 1
    $msg = GUIGetMsg()
    Select
    ; Login
        Case $msg = $Login
            If FileExists($Ini) Then
                FileDelete($Ini)
                Writer()
            EndIf

            If $Char > 10 Or $Char < 0 Then
                MsgBox(48, "WoW Auto Login", "Error!" & @CRLF & "You have typed a character number that is out of bounds." & @CRLF & "Click OK to continue.")
                Exit
            EndIf

            If WinExists($Title) Then
                ProcessClose("WoW.exe")
                Sleep(5000)
                Run($WoW)
            Else
                Run($WoW)
            EndIf

            Sleep($Delay)
            Send($Username)
            Send("{TAB}")
            Send($Password)
            Send("{ENTER}")
            Sleep($Delay2)

            $DW = @DesktopWidth
            $DH = @DesktopHeight
            If $DW = 800 And $DH = 600 Then
                MouseClick("left", 701, 84, 1, 10)
            Else
                If $DW = 1024 And $DH = 768 Then
                    MouseClick("left", 835, 110, 1, 10)
                Else
                    MsgBox(48, "WoW Auto Login", "Error!" & @CRLF & "Your desktop resolution isn't supported, please change your desktop resolution to either 800 x 600 or 1024 x 768." & @CRLF & "Click OK to continue.")
                    Exit
                EndIf
            EndIf

            Send("{DOWN " & $Char & "}")
            Sleep(1000)
            Send("{ENTER}")
            Exit

        Case $msg = $GUI_EVENT_CLOSE
            Exit
    EndSelect
WEnd

;--------------------------------------------- Functions----------------------------------------------

Func Reader()
    If FileExists($Ini) Then
        $User = IniRead($Ini, "Configuration", "UserName", "NotFound")
        $Pass = IniRead($Ini, "Configuration", "Password", "NotFound")
        $Char = IniRead($Ini, "Configuration", "Character", "NotFound")
        GUICtrlSetData($Username, $User)
        GUICtrlSetData($Password, $Pass)
        GUICtrlSetData($Character, $Char)
    Else
        Writer()
    EndIf
EndFunc  ;==>Reader

Func Writer()
    If Not FileExists($Ini) Then
        IniWrite($Ini, "Configuration", "UserName", $Username)
        IniWrite($Ini, "Configuration", "Password", $Password)
        IniWrite($Ini, "Configuration", "WoW", $WoW)
        IniWrite($Ini, "Configuration", "Character", $Character)
        IniWrite($Ini, "Configuration", "Title", "World of Warcraft")
        IniWrite($Ini, "Configuration", "Delay", "13000")
        IniWrite($Ini, "Configuration", "Delay2", "6000")
    Else
        Reader()
    EndIf
EndFunc  ;==>Writer

Could you tell me what to fix so that I don't always get 5 as character, 7 pass password and 9 as character no matter what?

Also could you tell me what I could do to improve my code?

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...