Jump to content

Run multiple setups from ini file


Go to solution Solved by Trong,

Recommended Posts

Hi All

I have a simple script with checkboxes and it installs what have been checked:

You can add more or less Global $Path

Spoiler

#include <GUIConstants.au3>
Global $Path1, $Path2, $Path3, $Path4, $Path5, $Path6, $Path7, $Path8
GUICreate("Software Setup:", 300, 250) 
$hlabel = GUICtrlCreateLabel("Select Software you wish to install", 50,10,300,20)
GUICtrlSetFont($hLabel, Default, 600)
$Path1 = GUICtrlCreateCheckbox("SetupName 1",20,40,300,20)
    guictrlsetstate(1,$gui_unchecked)
$Path2 = GUICtrlCreateCheckbox("SetupName 2",20,60,300,20)
    guictrlsetstate(2,$gui_unchecked)
$Path3 = GUICtrlCreateCheckbox("SetupName 3",20,80,300,20)
    guictrlsetstate(3,$gui_unchecked)
$Path4 = GUICtrlCreateCheckbox("SetupName 4",20,100,300,20)
    guictrlsetstate(4,$gui_unchecked)
$Path5 = GUICtrlCreateCheckbox("SetupName 5",20,120,300,20)
    guictrlsetstate(5,$gui_unchecked)
$Path6 = GUICtrlCreateCheckbox("SetupName 6",20,140,300,20)
    guictrlsetstate(6,$gui_unchecked)    
$Path7 = GUICtrlCreateCheckbox("SetupName 7",20,160,300,20)
    guictrlsetstate(7,$gui_unchecked)
$Path8 = GUICtrlCreateCheckbox("SetupName 8",20,180,300,20)
    guictrlsetstate(8,$gui_unchecked)    
$GoButton = GUICtrlCreateButton("RUN",100,210,100,25)
ControlFocus("Setup", "", "Button3")
GuiSetState()
While 1             
    $msg = guigetmsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE  
        ExitLoop    
    Case $msg = $GoButton                         
        if(GuiCtrlRead($Path1)  = 1) then     
    ;Do something here...
    EndIf       
        if(GuiCtrlRead($Path2)  = 1) then
    ;Do something here...
    EndIf
        if(GuiCtrlRead($Path3)  = 1) then
    ;Do something here...
    EndIf
        if(GuiCtrlRead($Path4)  = 1) then
    ;Do something here...    
    EndIf
        if(GuiCtrlRead($Path5)  = 1) then
    ;Do something here...    
    EndIf
        if(GuiCtrlRead($Path6)  = 1) then
    ;Do something here...    
    EndIf
        if(GuiCtrlRead($Path7)  = 1) then
    ;Do something here...
    EndIf
        if(GuiCtrlRead($Path8)  = 1) then
    ;Do something here...
    EndIf
    MsgBox(0,"","EXIT", 1)
        ExitLoop
    EndSelect
WEnd
Exit

So everything is OK but i would like make something easy without any GUI.

So i have INI file with the software i want to be installed. It looks like this:

[run]
1=setupname1.exe /S
2=setupname2.exe /SILENT
3=setupname3.exe /VERYSILENT
And so on...

Or i can make ini file like this:  (will be preferable)

[run]
setupname1.exe /S
setupname2.exe /SILENT
setupname3.exe /VERYSILENT
And so on...

So i need i need expert help, i want just run script without GUI wich will install everything from ini file, one by one from up till down.

Script Autoit, setup.ini file and all setup files will be in the same folder...

Can someone help me please?

Thanks advance

Link to comment
Share on other sites

Take a look at the IniRead() function!

Example script:

Global $sFilePath_INI = @ScriptDir & "\" & @ScriptName & ".INI"
Local $eXecute_Dir = @ScriptDir & "\" & IniRead($sFilePath_INI, "RUN", "EXECUTE_DIR", "")
Local $nCount = IniRead($sFilePath_INI, "RUN", "EXE_NUM", "0")
ConsoleWrite("- IniFilePath : " & $sFilePath_INI & @CRLF)
ConsoleWrite("- eXecute_Dir: " & $eXecute_Dir & @CRLF)
ConsoleWrite("- Count: " & $nCount & @CRLF)
Local $sExe_Name, $sExe_Parameters, $sCommand
If $nCount > 0 Then
    For $i = 1 To $nCount
        ConsoleWrite("+ Reading data number: " & $i & @CRLF)
        $sExe_Name = IniRead($sFilePath_INI, "RUN", "EXECUTE_" & $i, "")
        ConsoleWrite("- Exe_Name: " & $sExe_Name & @CRLF)
        $sExe_Parameters = IniRead($sFilePath_INI, "RUN", "EXECUTE_" & $i & "_parameters", "")
        ConsoleWrite("- Exe_Parameters: " & $sExe_Parameters & @CRLF)
        If StringStripWS($sExe_Name, 8) == "" Then
            ConsoleWrite("! Exe Name is Empty ! " & @CRLF)
        Else
            If FileExists($eXecute_Dir & "\" & $sExe_Name) Then
                If StringStripWS($sExe_Parameters, 8) == "" Then
                    ConsoleWrite("! No have Exe Parameters ! " & @CRLF)
                    $sCommand = '"' & $eXecute_Dir & "\" & $sExe_Name & '"'
                Else
                    $sCommand = '"' & $eXecute_Dir & "\" & $sExe_Name & '" ' & $sExe_Parameters
                EndIf
                ConsoleWrite("- eXecute: " & $sCommand & @CRLF)
                ;Your run function is here:
                RunWait($sCommand, $eXecute_Dir)
            Else
                ConsoleWrite("! " & $sExe_Name & " file does not exist in " & $eXecute_Dir & @CRLF)
            EndIf
        EndIf

    Next
    ConsoleWrite("! EXIT " & @CRLF)
EndIf

INI eg:

[RUN]
EXE_NUM=3
EXECUTE_DIR = bin
EXECUTE_1 = setupname1.exe
EXECUTE_1_parameters = /S

EXECUTE_2 = setupname2.exe
EXECUTE_2_parameters = /SILENT

EXECUTE_3 = setupname1.exe
EXECUTE_3_parameters = /VERYSILENT

 

 

With your request the script will be modified a bit:

Global $eXecute_Dir = @ScriptDir
Global $sFilePath_INI = $eXecute_Dir & "\" & "Setup.ini"
Local $nCount = IniRead($sFilePath_INI, "RUN", "EXE_NUM", "0")
ConsoleWrite("- Count: " & $nCount & @CRLF)
Local $sExe_Name, $sExe_Parameters, $sCommand
If $nCount > 0 Then
    For $i = 1 To $nCount
        ConsoleWrite("+ Reading data number: " & $i & @CRLF)
        $sExe_Name = IniRead($sFilePath_INI, "RUN", "EXECUTE_" & $i, "")
        ConsoleWrite("- Exe_Name: " & $sExe_Name & @CRLF)
        $sExe_Parameters = IniRead($sFilePath_INI, "RUN", "EXECUTE_" & $i & "_parameters", "")
        ConsoleWrite("- Exe_Parameters: " & $sExe_Parameters & @CRLF)
        If StringStripWS($sExe_Name, 8) == "" Then
            ConsoleWrite("! Exe Name is Empty ! " & @CRLF)
        Else
            If FileExists($eXecute_Dir & "\" & $sExe_Name) Then
                If StringStripWS($sExe_Parameters, 8) == "" Then
                    ConsoleWrite("! No have Exe Parameters ! " & @CRLF)
                    $sCommand = '"' & $eXecute_Dir & "\" & $sExe_Name & '"'
                Else
                    $sCommand = '"' & $eXecute_Dir & "\" & $sExe_Name & '" ' & $sExe_Parameters
                EndIf
                ConsoleWrite("- eXecute: " & $sCommand & @CRLF)
                ;Your run function is here:
                RunWait($sCommand, $eXecute_Dir)
            Else
                ConsoleWrite("! " & $sExe_Name & " file does not exist in " & $eXecute_Dir & @CRLF)
            EndIf
        EndIf
    Next
    ConsoleWrite("! EXIT " & @CRLF)
EndIf

Setup.ini content:

[RUN]
EXE_NUM=9

EXECUTE_1 = setupname1.exe
EXECUTE_1_parameters = /S

EXECUTE_2 = setupname2.exe
EXECUTE_2_parameters = /SILENT

EXECUTE_3 = setupname3.exe
EXECUTE_3_parameters = /VERYSILENT

EXECUTE_4 = setupname4.exe
EXECUTE_4_parameters = /CMD4

EXECUTE_5 = setupname5.exe
EXECUTE_5_parameters = /CMD5

EXECUTE_6 = setupname6.exe
EXECUTE_6_parameters = /CMD6

EXECUTE_7 = setupname7.exe
EXECUTE_7_parameters = /CMD7

EXECUTE_8 = setupname8.exe
EXECUTE_8_parameters = /CMD9

EXECUTE_9 = setupname9.exe
EXECUTE_9_parameters = /CMD9

 

Edited by Trong
fix eg ini

Regards,
 

Link to comment
Share on other sites

Trong

Thank you very much!

I've tested your code, works great but i must disable in ini file the line "EXE_NUM=3" because i need install evrything without confirmation

I tried to change EXE_NUM=3 to 1,2,3,4,5,6   etc but it doesn't work,  so i can't use it if i can't disable.

mikell

Thank you very much!

$lines = FileReadToArray("setup.txt")
For $i = 1 to UBound($lines)-1
   Msgbox(0,"", $lines[$i])    ; here you could use RunWait
Next

This way looks great and this is exactly what i am looking for.

I need simple txt or ini file with only one line per command insteed 2 or more. 

But with my knowlege i am not able to make working script using this code abowe.

Please if someone could make it for me I would be very grateful to you!

Link to comment
Share on other sites

  • Solution

When I submitted the full code it was tested and it certainly worked.


But anyway you can try with below code.

With the simpler option 2 but I'm not sure if it will work well or not:

Global $sFileSetupList = @ScriptDir & "\" & "SetupList.txt"
; Read the current script file into an array using the filepath.
Global $aArrayLine = FileReadToArray($sFileSetupList)
Global $iLineCount = @extended
If @error Then
    ConsoleWrite("! Error (" & @error & ") reading the file: " & $sFileSetupList & @CRLF)
    MsgBox(16, @ScriptName, "There was an error reading the file. @error: " & @error & @CRLF & "File: " & $sFileSetupList)           ; An error occurred reading the current script file.
Else
    For $i = 0 To $iLineCount - 1             ; Loop through the array. UBound($aArray) can also be used.
        ;MsgBox(0, @ScriptName, "Installing :" & $aArray[$i])               ; Display the contents of the array.
        If StringStripWS($aArrayLine[$i], 8) == "" Then
            ConsoleWrite("! Line is Empty ! " & @CRLF)
        Else
            ConsoleWrite("- eXecute: " & $aArrayLine[$i] & @CRLF)
            RunWait($aArrayLine[$i], @ScriptDir)
        EndIf
    Next
EndIf

SetupList.txt

setupname1.exe /S
setupname2.exe /SILENT
setupname3.exe /VERYSILENT

 

I haven't seen any of your code or error messages, did you go through the Autoit manual?

Regards,
 

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...