beardeus

[Resolved] Really need help; have no clue on how to read from an existing .ini and place data into a text box

22 posts in this topic

#1 ·  Posted (edited)

Hi,

So I just began using AutoIT yesterday to automate our installers at work. Let me first say that AutoIT is awesome and I'm wondering why I didn't start using this so long ago. Well, I have completely automated the installers but it enters the same text every time it runs. I want to be able to have .ini files that can be read and inserted into text boxes of the installer. I have looked at the help section about IniReadSection and IniRead and IniWrite but frankly I am so stumped. I would post code but I literally don't have any for reading from the file and then writing the data. Any direction would be great as I have not found anything that clearly explains this.

If I had an example of just reading from an .ini and placing that text into one text box it would be a huge help!

Edited by beardeus

Share this post


Link to post
Share on other sites



Hi, beardus, welcome to the forum. The basic syntax for reading from an ini would be something like this:

$sINI = <path to ini file>
$myText = IniRead($sINI, <Section Name>, <Key Name>, "")

You could then use ControlSend to send the string to the text box (without knowing what you're installing, or seeing the text box control, it is a little difficult to be more specific).

In addition to this, please keep in mind that most installers support silent switches. If the application you're installing supports this, it will definitely save you some headache from trying to manipulate the GUI. You might check into this option if it is a piece of commercial software.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

Hi Logan,

Thank you! Do I need to know the name of the text box to send text to it? Can I do it based on what the UI says?

Share this post


Link to post
Share on other sites

Let me give a little more info. I work for a software company that develops eDiscovery software for litigation purposes and the part of the installer I'm on has textboxes for a "Domain\UserID", "Password", along with some database credentials.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Hi Beardeus,

Welcome to the forums !

here is little prog I have been working on that may help you..

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <FTPEx.au3>

Local $HostName
Local $UserName
Local $PassWord
Local $testConn

$Form1 = GUICreate("FTP Login Credentials", 357, 162, 192, 124)
$HostNameB = GUICtrlCreateInput($HostName, 40, 24, 161, 21)
$UserNameB = GUICtrlCreateInput($UserName, 40, 56, 161, 21)
$PassWordB = GUICtrlCreateInput($PassWord, 40, 88, 161, 21)
$Save = GUICtrlCreateButton("Save", 232, 24, 73, 25)
GUICtrlSetTip(-1, "Saves login Info to INI File")
$Load = GUICtrlCreateButton("Load", 232, 56, 73, 25)
GUICtrlSetTip(-1, "Loads Previously Saved login Info from INI File")
$clear = GUICtrlCreateButton("Clear", 232, 88, 73, 25)
GUICtrlSetTip(-1, "Deletes any Previously saved INI Files")
$testConn = GUICtrlCreateButton("Test Connection", 132, 120, 90, 25)
GUICtrlSetTip(-1, "Test your Login Credentials")
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Load
            _iniLoad()
        Case $Save
            _iniSave()
        Case $clear
            _clearAll()
        Case $testConn
            _testConn()
    EndSwitch
WEnd

Assign

Func _clearAll()
    GUICtrlSetData($HostNameB, "")
    GUICtrlSetData($UserNameB, "")
    GUICtrlSetData($PassWordB, "")
    $iniFile = @ScriptDir & "\login.ini"
    If FileExists($iniFile) Then
        FileDelete($iniFile)
        MsgBox(4096, $iniFile, $iniFile & ":  Was Deleted", 2)
    Else
        MsgBox(4096, $iniFile, $iniFile & ":  Does not Exist", 2)
    EndIf

EndFunc   ;==>_clearAll


Func _iniLoad()

    If FileExists(@ScriptDir & "\login.ini") Then
        $HostName = IniRead(@ScriptDir & "\login.ini", "login", "HostName", "Default Value")
        $UserName = IniRead(@ScriptDir & "\login.ini", "login", "UserName", "Default Value")
        $PassWord = IniRead(@ScriptDir & "\login.ini", "login", "PassWord", "Default Value")
        GUICtrlSetData($HostNameB, $HostName)
        GUICtrlSetData($UserNameB, $UserName)
        GUICtrlSetData($PassWordB, $PassWord)
    Else
        MsgBox(16, "No File", "File Not Found")
    EndIf

EndFunc   ;==>_iniLoad


Func _iniSave()
    $HostName = GUICtrlRead($HostNameB)
    $UserName = GUICtrlRead($UserNameB)
    $PassWord = GUICtrlRead($PassWordB)
    IniWrite(@ScriptDir & "\login.ini", "login", "HostName", $HostName)
    IniWrite(@ScriptDir & "\login.ini", "login", "UserName", $UserName)
    IniWrite(@ScriptDir & "\login.ini", "login", "PassWord", $PassWord)

EndFunc   ;==>_iniSave


Func _testConn()

    _iniSave()
    Local $hOpen = _FTP_Open('MyFTP Control')
    Local $hConn = _FTP_Connect($hOpen, $HostName, $UserName, $PassWord)
    If $hConn = 0 Then
        MsgBox(0, "FTP Connection", "Connection not possible", 1)
    EndIf
    If $hConn > 0 Then
        MsgBox(0, "FTP Connection", "FTP Connected Successfully", 1)
    EndIf

    Local $Ftpc = _FTP_Close($hConn)
    Local $Ftpo = _FTP_Close($hOpen)

EndFunc   ;==>_testConn
 

 

Edited by l3ill
fixed last endif ;-)
1 person likes this

Share this post


Link to post
Share on other sites

 

Must Delete Last  EndIf

Untitled.thumb.jpg.652056883da6165090412

Share this post


Link to post
Share on other sites

Taking a look now I3ill, thanks.

Share this post


Link to post
Share on other sites
132, 120, 90, 25)

 

Hmmm...are these coordinates? I haven't been using them. I am a beginner so my installs mainly consist of ("{Tab}") or ("!a") to maneuver. I first started using sleeps but that wasn't making things go smoothly. I instead used WinWaitActive which has worked like a charm. I wasn't aware I could use that and then select text from within the install window. I first thought I had to select only text from the install title and the installer has the same title throughout. Now I just have a text box and need to input data there. My script of the installation looks VERY primitive compared to what you guys have.

Thanks for all of the welcomes. I am remoting into my work computer to figure this out. It is fun/exciting for me to learn something new.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

maybe this will help

#include <GUIConstantsEx.au3>
#include <StructureConstants.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

Global $g_idMemo

_Example_Defaults()

Func _Example_Defaults()

    ; Create GUI
    $hGui = GUICreate("GetOpenFileName use defaults", 400, 296)
    $g_idMemo = GUICtrlCreateEdit("", 2, 32, 396, 226, $WS_HSCROLL)
    GUICtrlSetFont($g_idMemo, 9, 400, 0, "Courier New")
    $id_Dialog = GUICtrlCreateButton("Open File", 155, 270, 90, 20)
    GUISetState(@SW_SHOW)

    While 1
        Switch GUIGetMsg()
            Case $id_Dialog

                $aFile = FileOpenDialog("", @DesktopDir & "\", "(*.ini)")


     $line = FileReadLine($aFile,2)  ;~ Read Line 2

                        MemoWrite($line)

            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd
    GUIDelete($hGui)
EndFunc   ;==>_Example_Defaults

; Write a line to the memo control
Func MemoWrite($sMessage)
    GUICtrlSetData($g_idMemo, $sMessage  & @CRLF, 1)
EndFunc   ;==>MemoWrite
;~ Read Line 2 in File.ini
Edited by ahmeddzcom
1 person likes this

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

This reading All :

#include <GUIConstantsEx.au3>
#include <StructureConstants.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>
#include <File.au3>

Global $g_idMemo

_Example_Defaults()

Func _Example_Defaults()

    ; Create GUI
    $hGui = GUICreate("GetOpenFileName use defaults", 400, 296)
    $g_idMemo = GUICtrlCreateEdit("", 2, 32, 396, 226, $WS_HSCROLL)
    GUICtrlSetFont($g_idMemo, 9, 400, 0, "Courier New")
    $id_Dialog = GUICtrlCreateButton("Open File", 155, 270, 90, 20)
    GUISetState(@SW_SHOW)

    While 1
        Switch GUIGetMsg()
            Case $id_Dialog

                $aFile = FileOpenDialog("", @DesktopDir & "\", "(*.ini)")


     $line = FileReadLine($aFile)


     For $i = 1 to _FileCountLines($aFile)
    $line = FileReadLine($aFile, $i)
MemoWrite($line)
Next



            Case $GUI_EVENT_CLOSE
                ExitLoop
        EndSwitch
    WEnd
    GUIDelete($hGui)
EndFunc   ;==>_Example_Defaults

; Write a line to the memo control
Func MemoWrite($sMessage)
    GUICtrlSetData($g_idMemo, $sMessage  & @CRLF, 1)
EndFunc   ;==>MemoWrite

 

Edited by ahmeddzcom

Share this post


Link to post
Share on other sites
132, 120, 90, 25)

 

Hmmm...are these coordinates? I haven't been using them. I am a beginner so my installs mainly consist of ("{Tab}") or ("!a") to maneuver. I first started using sleeps but that wasn't making things go smoothly. I instead used WinWaitActive which has worked like a charm. I wasn't aware I could use that and then select text from within the install window. I first thought I had to select only text from the install title and the installer has the same title throughout. Now I just have a text box and need to input data there. My script of the installation looks VERY primitive compared to what you guys have.

Thanks for all of the welcomes. I am remoting into my work computer to figure this out. It is fun/exciting for me to learn something new.

Yes, these are GUI coords aka. Function Parameters.

Probably not necessary for your project, I was just working on this when I saw your question and thought it might help.

If you are just trying to place text into edit boxes from an ini file then you will need JLogan3o13 's suggestion

IniRead coupled with ControlSetText

Give it a shot and come back if you get stuck, don't forget to show your work (code) as it makes it easier to help & troubleshoot ;-)

cya,

Bill

Share this post


Link to post
Share on other sites

Here a different snippet changed to a bit to reproduce the above mentioned:

(the sleeps are only there so you can see it work)

$sSelect =  IniRead(@ScriptDir & "\login.ini", "login", "HostName", "Default Value")

Run("rundll32.exe shell32.dll,#61")

WinWaitActive("Run")
Sleep(1000)
ControlSetText("Run", "", "[CLASS:Edit; INSTANCE:1]", $sSelect)
Sleep(1000)
ControlClick("Run", "", "[CLASS:Button; INSTANCE:2]")
[login]
HostName=my ini text
UserName=
PassWord=

save this as "login.ini"

Share this post


Link to post
Share on other sites

I'm sorry. This is just all too confusing for me. I don't know enough of the variables used to be able to take an existing ini, read from it and then place the ini data to text boxes. Thanks for everyone's help. I just might have to scrap the whole ini part.

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

Hi JohnOne, I'm a total AutoIT noob that started using it on Thursday or Friday. This is what I have. Ignore the directory name. The text box is just returning the text "$Answer". I thought it would be returning the value of the .ini in the text box that is associated with $Answer.

$Answer=IniRead("Directory","LocalDomain","Domain","FAILURE!")

Winactivate ("Installer", "SQL")

ControlSend("Installer","","","$Answer")

Edited by beardeus

Share this post


Link to post
Share on other sites

Never mind. Figured it out!

Share this post


Link to post
Share on other sites

#18 ·  Posted (edited)

Sure johnOne. Again, I am a total nub here so my code my seem very elementary.

#include <WinAPIFiles.au3>
Sleep(1000)

;Read from the ini file to populate text boxes
$Answer=IniRead("C:\Users\TESTING\Desktop\Automated Install.ini","LocalDomain","Domain","FAILURE!")
Sleep(1000)
Winactivate ("Enterprise - InstallShield Wizard", "SQL")
ControlSend("Enterprise - InstallShield Wizard","SQL","",$Answer)
Send ("{Tab}")
Send ("{Tab}")
$Answer1=IniRead("C:\Users\TESTING\Desktop\Automated Install.ini","LocalDomain","DomainPassword","FAILURE!")
ControlSend("Enterprise - InstallShield Wizard","SQL","",$Answer1)
Send ("{Tab}")
$Answer2=IniRead("C:\Users\TESTING\Desktop\Automated Install.ini","SQL","Server","FAILURE!")
ControlSend("Ipro eCapture Enterprise - InstallShield Wizard","SQL","",$Answer2)
Send ("{Tab}")
Send ("{Tab}")
$Answer3=IniRead("C:\Users\TESTING\Desktop\Automated Install.ini","SQL","Database","FAILURE!")
ControlSend("Enterprise - InstallShield Wizard","SQL","",$Answer3)
Send ("{Tab}")
Send ("{Tab}")
$Answer4=IniRead("C:\Users\TESTING\Desktop\Automated Install.ini","SQL","LoginID","FAILURE!")
ControlSend("Enterprise - InstallShield Wizard","SQL","",$Answer4)
Send ("{Tab}")
$Answer5=IniRead("C:\Users\TESTING\Desktop\Automated Install.ini","SQL","Password","FAILURE!")
ControlSend("Enterprise - InstallShield Wizard","SQL","",$Answer5)
Sleep(200)
ControlClick("Enterprise - InstallShield Wizard","","Validate")
Send("{Enter}")
WinWaitActive ("Enterprise - InstallShield Wizard", "Passed")
Send("{Enter}")
Sleep (2500)
WinWaitActive ("Enterprise - InstallShield Wizard")
Sleep(200)
Send("!n")
Sleep(200)
Send("{Enter}")
;Sleep (450000)
WinWaitActive ("Enterprise - InstallShield Wizard", "Completed")
Sleep (1000)
Send("{Enter}")

Sleep (10000)

 

Edited by beardeus

Share this post


Link to post
Share on other sites

Another tip since you mentioned your trouble with variables here is a perfect chance to learn.

Change your paths to variables and then you will only have to change one path instead of many.

Example:

#include <WinAPIFiles.au3>

$installPath = "C:\Users\TESTING\Desktop\Automated Install.ini"   ;  in the future only need to change this

;Read from the ini file to populate text boxes
$Answer=IniRead($installPath,"LocalDomain","Domain","FAILURE!")
Sleep(1000)
Winactivate ("Enterprise - InstallShield Wizard", "SQL")
ControlSend("Enterprise - InstallShield Wizard","SQL","",$Answer)
Send ("{Tab}")
Send ("{Tab}")
$Answer1=IniRead($installPath,"LocalDomain","DomainPassword","FAILURE!")
ControlSend("Enterprise - InstallShield Wizard","SQL","",$Answer1)
Send ("{Tab}")
$Answer2=IniRead($installPath,"SQL","Server","FAILURE!")
ControlSend("Ipro eCapture Enterprise - InstallShield Wizard","SQL","",$Answer2)

;;;===and so on...

 

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