Jump to content
Sign in to follow this  
Tulip

Run or RunWait function are not installing the softwares.Pl help me

Recommended Posts

Tulip

Hi ,

I have got the code sample from this forum which I have added below.

#include <GUIConstants.au3>
#include <GuiListView.au3>
#include <Array.au3>
#include <File.au3>

Global $iniFile = @ScriptDir & "Config.ini"
Global $scriptDir = @ScriptDir
; Main GUI
$Form1 = GUICreate("Software Installer", 633, 451)

$Tab1 = GUICtrlCreateTab(16, 8, 601, 377)
$TabSheet1 = GUICtrlCreateTabItem("Software Tools")
$ListView1 = GUICtrlCreateListView("Software Name|Description", 24, 40, 582, 334)
_GUICtrlListView_SetExtendedListViewStyle($ListView1, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES, $LVS_EX_GRIDLINES))
GUICtrlSendMsg(-1, 0x101E, 0, 200)
GUICtrlSendMsg(-1, 0x101E, 1, 375)

GUICtrlCreateTabItem("") ; This ends the tab item creation
$Button1 = GUICtrlCreateButton("Install Selected Software", 398, 395, 219, 25, 0)
$MenuItem1 = GUICtrlCreateMenu("File")
$MenuItem2 = GUICtrlCreateMenuItem("Unselect All", $MenuItem1)
$MenuItem3 = GUICtrlCreateMenuItem("Exit", $MenuItem1)
$MenuItem4 = GUICtrlCreateMenu("Help")
$MenuItem5 = GUICtrlCreateMenuItem("Help Topics", $MenuItem4)
$MenuItem6 = GUICtrlCreateMenuItem("About", $MenuItem4)
_Populate()
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            _InstallSelectedSoftware()
        Case $MenuItem2
            _UnselectAll()
        Case $MenuItem3
            Exit
        Case $MenuItem5
            _HelpTopics()
        Case $MenuItem6
            _AboutProject()
    EndSwitch
WEnd

Func _Populate()
    ; Find all files in the Software folder and populate the tabs with the installers.
    $f = FileFindFirstFile("Software/*.*")
    Dim $array[1]
    $i = 0
    Do
        $s = FileFindNextFile($f)
        If Not @error Then
            $array[$i] = $s
            $i += 1
            ReDim $array[$i + 1]
        EndIf
    Until @error
    ReDim $array[$i]

    For $i = 1 To UBound($array) Step 1
        $category = IniRead($iniFile, $array[$i - 1], "Category", "1")
        $desc = IniRead($iniFile, $array[$i - 1], "Desc", "")
        If $category = 1 Then
            GUICtrlCreateListViewItem($array[$i - 1] & "|" & $desc, $ListView1)
        EndIf
    Next
EndFunc   ;==>_Populate

Func _InstallSelectedSoftware()
    Dim $sArray[1]
    
   MsgBox(0, "_InstallSelectedSoftware", "Entering function!")

   ; Find which items were selected by user on Software Tools tab
    $count = _GUICtrlListView_GetItemCount($ListView1)
    $aCount = 0
    For $i = 1 To $count Step 1
        If _GUICtrlListView_GetItemChecked($ListView1, $i - 1) = True Then
            $sArray[$aCount] = _GUICtrlListView_GetItemText($ListView1, $i - 1)
            ReDim $sArray[UBound($sArray) + 1]
            $aCount += 1
        EndIf
    Next

    ; Begin installing selected software
    ProgressOn("Software Installer", "Installing", "", -1, -1, 16)
    For $i = 1 To UBound($sArray) - 1 Step 1
        $fileName = $sArray[$i - 1]
        ;==>MsgBox(0, "", "Variable $fileName contains " & $fileName)
        $switch = IniRead($iniFile, $fileName, "Switch", "/qn")
        ;==?MsgBox(0, "", "Variable $switch contains " & $switch) 
        $extension = StringRight($fileName, 3)
        ;==>MsgBox(0, "", "Variable $extension contains " & $extension)  
        If $extension = "msi" Then
           MsgBox(0, "", "msi type installation " & $scriptDir)
            Run("msiexec /i " & '"' & $scriptDir & "./Software/" & $fileName & '" ' & $switch)
         Else
            MsgBox(0, "", "exe type installation " & $scriptDir)
            RunWait('"' & $scriptDir & "./Software/" & $fileName & '"' & " " & $switch) ; For EXE installers
        EndIf
        ProgressSet($i / (UBound($sArray) - 1) * 100, Round($i / (UBound($sArray) - 1) * 100, 0) & "%", "Installing " & $i & " of " & UBound($sArray) - 1)
    Next
    ProgressOff()
EndFunc   ;==>_InstallSelectedSoftware

Func _UnselectAll()
    $count = _GUICtrlListView_GetItemCount($ListView1)
    For $i = 1 To $count Step 1
        _GUICtrlListView_SetItemChecked($ListView1, $i - 1, False)
    Next

EndFunc   ;==>_UnselectAll

Func _HelpTopics()
    $Form2 = GUICreate("Help Topics", 633, 447)
    $Label1 = GUICtrlCreateLabel("", 8, 16, 612, 425)
    GUICtrlSetData(-1, "This program uses silent switches to install software without user interaction. To use this functionality, you can edit the Config.ini file to add software and their switches. Example: " & @CRLF & @CRLF & "[MetalScrollSetup_1.0.11.exe]" & @CRLF & "Switch=/S" & @CRLF & "Desc=A Meta Scroll Setup" & @CRLF & "Category=1" & @CRLF & @CRLF & "The name of the file is the first line in the brackets. The line with Switch= is the section for the unattended switch. The Desc= is the description for the program. The Category= is the tab you want the program to show up on the interface." & @CRLF & @CRLF & "Here are some common switches for various installers:" & @CRLF & @CRLF & "/silent used for Inno Setup installers" & @CRLF & "/verysilent used for Inno Setup installers" & @CRLF & "/S used for Nullsoft (aka NSIS) installers" & @CRLF & "/s used for Wise installers" & @CRLF & "-s used for Ghost installers" & @CRLF & "-ms used for Mozilla installers" & @CRLF & "/quiet used for Microsoft installers" & @CRLF & "/qb used for Microsoft installers" & @CRLF & "/qn used for Microsoft installers" & @CRLF & "/passive used for Microsoft installers" & @CRLF & "/Q used for Microsoft installers" & @CRLF & @CRLF & "Note: Some installers are case sensitive (Ghost and Nullsoft for sure).")
    GUISetState(@SW_SHOW)

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                GUIDelete($Form2)
                ExitLoop
        EndSwitch
    WEnd
EndFunc   ;==>_HelpTopics

Func _AboutProject()
    $Form3 = GUICreate("About", 413, 196)
    $Label1a = GUICtrlCreateLabel("", 24, 64, 364, 113)
    $Label2a = GUICtrlCreateLabel("Software Installer 1.0", 24, 8, 375, 41)
    GUICtrlSetFont(-1, 24, 800, 2, "MS Sans Serif")
    GUICtrlSetColor(-1, 0x000080)
    GUISetState(@SW_SHOW)
    $aboutData = "This program was written|in a programming language called Autoit||Brought to you by abberration"
    $sData = StringSplit($aboutData, "|", 2)
    $string = ""
    For $i = 1 To UBound($sData) Step 1
        $string = $string & @CRLF & $sData[$i - 1] & @CRLF
        GUICtrlSetData($Label1a, $string)
        Sleep(1000)
    Next

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                GUIDelete($Form3)
                ExitLoop
        EndSwitch
    WEnd
 EndFunc   ;==>_AboutProject

I am getting the Software list populating and able to check mark the software software. however when I select the software and tried installing , it is not installing the software. it just pops up progress bar and clears off. followins is the piece of code using for installing the software. I tried debugging the variable names and all. no typo error. suspect execution of script.

            Run("msiexec /i " & '"' & $scriptDir & "./Software/" & $fileName & '" ' & $switch)
            RunWait('"' & $scriptDir & "./Software/" & $fileName & '"' & " " & $switch) ; For EXE installers

Please help me on this as I have to finish this task ASAP....

Thanks in Advance...

Edited by Tulip

Share this post


Link to post
Share on other sites
MHz

Perhaps not reading from the ini file

Global $iniFile = @ScriptDir & "\Config.ini"

The handle for FileFindFirstFile is not checked if it is valid so I get a Redim error.

FileFindFirstFile using a relative path yet Run and RunWait uses $scriptDir which can possibly be 2 different paths.

Fix those items and then test it for any further problems that may exist.

Share this post


Link to post
Share on other sites
Tulip

Hi MHZ,

Thanks for your reply. I am getting , I added msgbox there by printing the file names, it is going to all the files from the config file. because I am storing all the file names in Array.

some how the software is not getting installed.

I created sample script file by adding the following alone in the script ..( tried with removing swtich /S)

 RunWait("C:UsersUIDW6331Desktoptcm801x64INSTALL.EXE /S")

It is not getting installed.. ( able to install that .exe by clicking on exe file and as a batch script. but not thru AutoIt script)

Share this post


Link to post
Share on other sites
MHz

Add #RequireAdmin to the top of the script as installers using Run and RunWait may need it.

I am currently looking through all of the variables to see what is local is what is not.

Share this post


Link to post
Share on other sites
MHz

Some changes made. Not sure if error free. Just improved in areas I noticed like localizing variables, returning error if a condition is invalid to continue, skip collect folders in FFNF, only exe and msi in FFNF etc.

; Edit: Code removed as not worked well. See new code below that is posted.
Edited by MHz

Share this post


Link to post
Share on other sites
Tulip

Hi MHz,

Thanks for helping me..I tried your modified code, it always shows one exe file in the list.

I have following Quetion to you..

1)  I added Add #RequireAdmin at the begining of my file. it is working and taking to installation wizard for exe. however for msi type file, it is not getting installed at all.. 

2) and also the following line

 $switch = IniRead($iniFile, $fileName, "Switch", "/qn")
 

it reads from the file and look for the section $fileName and returns the value of the attribute 'Switch'. if it not specified in the file, it return the default one which '/qn' mentioned here..in my case, it is not able to get the value of the attribute Switch.. I have used the similar function for getting the value of category, which is working.

Here is .ini file

[MetalScrollSetup_1.0.11.exe]
Switch=/S
Desc=Meta scroll Setup
Category=1

[SonicFileFinder2.3.msi]
Switch=/qn
Desc=Desktop weather station
Category=1

3) Currently for exe type, if i do not mention /S( which is silent mode)  it is taking me to installation wizard when I click on install software after checking that exe file. otherwise( If i mention /S) nothing is coming up..

so how to make software to get installed with out user interaction..

Basically my task is to install multiple softwares with out user intervention.. User just selects the software leaves the pc, it should just get installed one by one..

Share this post


Link to post
Share on other sites
MHz

I have done some testing with this one on some blank compiled scripts. See if it works for you. msi default switch is /qn and exe default switch is /S. It reads the ini file info as noticed when I forced the Msgboxes to show.

#RequireAdmin

#include <GUIConstants.au3>
#include <GuiListView.au3>
#include <Array.au3>
#include <File.au3>

Global $iniFile = @ScriptDir & "\Config.ini"
Global $scriptDir = @ScriptDir
; Main GUI
$Form1 = GUICreate("Software Installer", 633, 451)

$Tab1 = GUICtrlCreateTab(16, 8, 601, 377)
$TabSheet1 = GUICtrlCreateTabItem("Software Tools")
$ListView1 = GUICtrlCreateListView("Software Name|Description", 24, 40, 582, 334)
_GUICtrlListView_SetExtendedListViewStyle($ListView1, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES, $LVS_EX_GRIDLINES))
GUICtrlSendMsg(-1, 0x101E, 0, 200)
GUICtrlSendMsg(-1, 0x101E, 1, 375)

GUICtrlCreateTabItem("") ; This ends the tab item creation
$Button1 = GUICtrlCreateButton("Install Selected Software", 398, 395, 219, 25, 0)
$MenuItem1 = GUICtrlCreateMenu("File")
$MenuItem2 = GUICtrlCreateMenuItem("Unselect All", $MenuItem1)
$MenuItem3 = GUICtrlCreateMenuItem("Exit", $MenuItem1)
$MenuItem4 = GUICtrlCreateMenu("Help")
$MenuItem5 = GUICtrlCreateMenuItem("Help Topics", $MenuItem4)
$MenuItem6 = GUICtrlCreateMenuItem("About", $MenuItem4)
_Populate()
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            _InstallSelectedSoftware()
            WinActivate($Form1)
        Case $MenuItem2
            _UnselectAll()
        Case $MenuItem3
            Exit
        Case $MenuItem5
            _HelpTopics()
        Case $MenuItem6
            _AboutProject()
    EndSwitch
WEnd

Func _Populate()
    ; Find all files in the Software folder and populate the tabs with the installers.
    Local $array[1], $f, $i, $s, $category, $desc
    ; Not Local $scriptDir, $iniFile, $ListView1
    $i = -1
    $f = FileFindFirstFile($scriptDir & "\Software\*.*")
    If $f = -1 Then Return SetError(1, 0, 0)
    While 1
        $s = FileFindNextFile($f)
        If @error Then ExitLoop
        If @extended Then ContinueLoop; as want no folders
        Switch StringRight($s, 4)
            Case '.exe', '.msi'
                $i += 1
                ReDim $array[$i + 1]
                $array[$i] = $s
        EndSwitch
    WEnd
    
    For $i = 0 To UBound($array) -1
        $category = IniRead($iniFile, $array[$i], "Category", "1")
        $desc = IniRead($iniFile, $array[$i], "Desc", FileGetVersion($array[$i], 'ProductName'))
        If $category == "1" Then
            GUICtrlCreateListViewItem($array[$i] & "|" & $desc, $ListView1)
        EndIf
    Next
EndFunc   ;==>_Populate

Func _InstallSelectedSoftware()
    Local $sArray[1], $count, $aCount, $fileName, $switch, $extension, $i
    ; Not Local $ListView1, $iniFile, $scriptDir
    
    MsgBox(0, "_InstallSelectedSoftware", "Entering function!")

   ; Find which items were selected by user on Software Tools tab
    $count = _GUICtrlListView_GetItemCount($ListView1)
    $aCount = 0
    For $i = 1 To $count Step 1
        If _GUICtrlListView_GetItemChecked($ListView1, $i - 1) = True Then
            $sArray[$aCount] = _GUICtrlListView_GetItemText($ListView1, $i - 1)
            ReDim $sArray[UBound($sArray) + 1]
            $aCount += 1
        EndIf
    Next

    ; Begin installing selected software
    ProgressOn("Software Installer", "Installing", "", -1, -1, 16)
    For $i = 1 To UBound($sArray) - 1
        $fileName = $sArray[$i - 1]
        ;==>MsgBox(0, "", "Variable $fileName contains " & $fileName)
        $extension = StringRight($fileName, 4)
        ;==>MsgBox(0, "", "Variable $extension contains " & $extension)  
        If $extension = ".msi" Then
            $switch = IniRead($iniFile, $fileName, "Switch", "/qn")
            ;==?MsgBox(0, "", "Variable $switch contains " & $switch)
            Run("msiexec /i " & '"' & $scriptDir & "\Software\" & $fileName & '" ' & $switch)
            If @error Then   MsgBox(0, "msi type installation ", '"' & $scriptDir & "\Software\" & $fileName & '" ' & $switch)
        Else
            $switch = IniRead($iniFile, $fileName, "Switch", "/S")
            ;==?MsgBox(0, "", "Variable $switch contains " & $switch)
            RunWait('"' & $scriptDir & "\Software\" & $fileName & '"' & " " & $switch) ; For EXE installers
            If @error Then MsgBox(0, "exe type installation", '"' & $scriptDir & "\Software\" & $fileName & '" ' & $switch)
        EndIf
        ProgressSet($i / (UBound($sArray) - 1) * 100, Round($i / (UBound($sArray) - 1) * 100, 0) & "%", "Installing " & $i & " of " & UBound($sArray) - 1)
    Next
    Sleep(1000)
    ProgressOff()
EndFunc   ;==>_InstallSelectedSoftware

Func _UnselectAll()
    Local $count, $i
    ; Not Local $ListView1
    $count = _GUICtrlListView_GetItemCount($ListView1)
    For $i = 1 To $count Step 1
        _GUICtrlListView_SetItemChecked($ListView1, $i - 1, False)
    Next

EndFunc   ;==>_UnselectAll

Func _HelpTopics()
    Local $Form2, $Label1, $nMsg
    $Form2 = GUICreate("Help Topics", 633, 447)
    $Label1 = GUICtrlCreateLabel("", 8, 16, 612, 425)
    GUICtrlSetData(-1, "This program uses silent switches to install software without user interaction. To use this functionality, you can edit the Config.ini file to add software and their switches. Example: " & @CRLF & @CRLF & "[MetalScrollSetup_1.0.11.exe]" & @CRLF & "Switch=/S" & @CRLF & "Desc=A Meta Scroll Setup" & @CRLF & "Category=1" & @CRLF & @CRLF & "The name of the file is the first line in the brackets. The line with Switch= is the section for the unattended switch. The Desc= is the description for the program. The Category= is the tab you want the program to show up on the interface." & @CRLF & @CRLF & "Here are some common switches for various installers:" & @CRLF & @CRLF & "/silent used for Inno Setup installers" & @CRLF & "/verysilent used for Inno Setup installers" & @CRLF & "/S used for Nullsoft (aka NSIS) installers" & @CRLF & "/s used for Wise installers" & @CRLF & "-s used for Ghost installers" & @CRLF & "-ms used for Mozilla installers" & @CRLF & "/quiet used for Microsoft installers" & @CRLF & "/qb used for Microsoft installers" & @CRLF & "/qn used for Microsoft installers" & @CRLF & "/passive used for Microsoft installers" & @CRLF & "/Q used for Microsoft installers" & @CRLF & @CRLF & "Note: Some installers are case sensitive (Ghost and Nullsoft for sure).")
    GUISetState(@SW_SHOW)

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                GUIDelete($Form2)
                ExitLoop
        EndSwitch
    WEnd
EndFunc   ;==>_HelpTopics

Func _AboutProject()
    Local $Form3, $Label1a, $Label2a, $aboutData, $sData, $string, $nMsg
    ; Not Local $Form1
    $Form3 = GUICreate("About", 413, 196)
    $Label1a = GUICtrlCreateLabel("", 24, 64, 364, 113)
    $Label2a = GUICtrlCreateLabel("Software Installer 1.0", 24, 8, 375, 41)
    GUICtrlSetFont(-1, 24, 800, 2, "MS Sans Serif")
    GUICtrlSetColor(-1, 0x000080)
    GUISetState(@SW_SHOW)
    $aboutData = "This program was written|in a programming language called Autoit||Brought to you by abberration"
    $sData = StringSplit($aboutData, "|", 2)
    $string = ""
    For $i = 1 To UBound($sData) -1
        $string &= @CRLF & $sData[$i - 1] & @CRLF
        GUICtrlSetData($Label1a, $string)
        Sleep(1000)
    Next

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                GUIDelete($Form3)
                ExitLoop
        EndSwitch
    WEnd
 EndFunc   ;==>_AboutProject

Some changes to the array usage was needed so hopefully works ok.

Edit: Removed a debug Msgbox I left in after _Populate() call. And a ConsoleWrite in _Populate().

Edited by MHz

Share this post


Link to post
Share on other sites
Tulip

Thanks a lot MHz. this is working perfectly well. I am sorry for questing you i am very new to AutoIT .just 2 days old..

1) How can I install a tool in a partcular directory. now it is installing in the C:programfile(x86), I want all these softwares to be installed D:ToolCommon where for the first time, if the directory structure is not existed it should get created and start installing the softwares into that .

2) currently I am placing the exe or msi files in the software directory and searching for msi or exe. now I will have lots of softwares, for every software there will be a directory, within the directory I wil have exe file and supporting files. so how can I do that. like Software/VisualStudio/VisualStudio.exe

till now i had Software/VisualStudio.exe ,now  level down..

Share this post


Link to post
Share on other sites
MHz

1) Depends on the installer type e.g. Inno setup, NSIS, Installshield etc. and what options are set by the creator of the installer. Have a look at SendToA3X which has Identify Installer and the text files it reads in the install directory has much info about switches that can be used.

2)  The code needs adaption to allow for the subfolders. This is no small task. At the moment the reading of the ini file is based on just a filename and now you want subfolder paths which means that part needs a possible change to suit paths to the file. Perhaps this is something that abberration may consider doing.

I have a similar program but it searches for scripts to run each installer. Perhaps a change to do that then you can do more by having a script for each installer. Then the path to the installer can be whatever you want in the script. I use something like >this.

Edit fixed a typo

Edited by MHz

Share this post


Link to post
Share on other sites
MHz

I added a subfolder search. See how it works for you.

#RequireAdmin

#include <GUIConstants.au3>
#include <GuiListView.au3>
#include <Array.au3>
#include <File.au3>

Global $iniFile = @ScriptDir & "\Config.ini"
Global $scriptDir = @ScriptDir
; Main GUI
$Form1 = GUICreate("Software Installer", 633, 451)

$Tab1 = GUICtrlCreateTab(16, 8, 601, 377)
$TabSheet1 = GUICtrlCreateTabItem("Software Tools")
$ListView1 = GUICtrlCreateListView("Software Name|Description", 24, 40, 582, 334)
_GUICtrlListView_SetExtendedListViewStyle($ListView1, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES, $LVS_EX_GRIDLINES))
GUICtrlSendMsg(-1, 0x101E, 0, 200)
GUICtrlSendMsg(-1, 0x101E, 1, 375)

GUICtrlCreateTabItem("") ; This ends the tab item creation
$Button1 = GUICtrlCreateButton("Install Selected Software", 398, 395, 219, 25, 0)
$MenuItem1 = GUICtrlCreateMenu("File")
$MenuItem2 = GUICtrlCreateMenuItem("Unselect All", $MenuItem1)
$MenuItem3 = GUICtrlCreateMenuItem("Exit", $MenuItem1)
$MenuItem4 = GUICtrlCreateMenu("Help")
$MenuItem5 = GUICtrlCreateMenuItem("Help Topics", $MenuItem4)
$MenuItem6 = GUICtrlCreateMenuItem("About", $MenuItem4)
_Populate()
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            _InstallSelectedSoftware()
            WinActivate($Form1)
        Case $MenuItem2
            _UnselectAll()
        Case $MenuItem3
            Exit
        Case $MenuItem5
            _HelpTopics()
        Case $MenuItem6
            _AboutProject()
    EndSwitch
WEnd

Func _Populate()
    ; Find all files in the Software folder and populate the tabs with the installers.
    Local $array[1], $f, $i, $s, $category, $desc, $s2
    ; Not Local $scriptDir, $iniFile, $ListView1
    $i = -1
    $f = FileFindFirstFile($scriptDir & "\Software\*.*")
    If $f = -1 Then Return SetError(1, 0, 0)
    While 1
        $s = FileFindNextFile($f)
        If @error Then ExitLoop
        If @extended Then
            $subf = FileFindFirstFile($scriptDir & "\Software\" & $s & '\*')
            If $subf <> -1 Then
                While 1
                    $s2 = FileFindNextFile($subf)
                    If @error Then ExitLoop
                    If @extended Then ContinueLoop
                    Switch StringRight($s2, 4)
                        Case '.exe', '.msi'
                            $i += 1
                            ReDim $array[$i + 1]
                            $array[$i] = $s & '\' & $s2
                            ConsoleWrite($array[$i] & @CRLF)
                    EndSwitch
                WEnd
                FileClose($subf)
            EndIf
        EndIf
        If @extended Then ContinueLoop; as want no folders
        Switch StringRight($s, 4)
            Case '.exe', '.msi'
                $i += 1
                ReDim $array[$i + 1]
                $array[$i] = $s
        EndSwitch
    WEnd
    FileClose($f)
    
    For $i = 0 To UBound($array) -1
        $category = IniRead($iniFile, $array[$i], "Category", "1")
        $desc = IniRead($iniFile, $array[$i], "Desc", FileGetVersion($scriptDir & "\Software\" & $array[$i], 'ProductName'))
        If $category == "1" Then
            GUICtrlCreateListViewItem($array[$i] & "|" & $desc, $ListView1)
        EndIf
    Next
EndFunc   ;==>_Populate

Func _InstallSelectedSoftware()
    Local $sArray[1], $count, $aCount, $fileName, $switch, $extension, $i
    ; Not Local $ListView1, $iniFile, $scriptDir
    
    ;==?MsgBox(0, "_InstallSelectedSoftware", "Entering function!")

    ; Find which items were selected by user on Software Tools tab
    $count = _GUICtrlListView_GetItemCount($ListView1)
    $aCount = 0
    For $i = 1 To $count Step 1
        If _GUICtrlListView_GetItemChecked($ListView1, $i - 1) = True Then
            $sArray[$aCount] = _GUICtrlListView_GetItemText($ListView1, $i - 1)
            ReDim $sArray[UBound($sArray) + 1]
            $aCount += 1
        EndIf
    Next

    ; Begin installing selected software
    ProgressOn("Software Installer", "Installing", "", -1, -1, 16)
    For $i = 1 To UBound($sArray) - 1
        $fileName = $sArray[$i - 1]
        ;==>MsgBox(0, "", "Variable $fileName contains " & $fileName)
        $extension = StringRight($fileName, 4)
        ;==>MsgBox(0, "", "Variable $extension contains " & $extension)
        If $extension = ".msi" Then
            $switch = IniRead($iniFile, $fileName, "Switch", "/qn")
            ;==?MsgBox(0, "", "Variable $switch contains " & $switch)
            Run("msiexec /i " & '"' & $scriptDir & "\Software\" & $fileName & '" ' & $switch)
            If @error Then   MsgBox(0, "msi type installation ", '"' & $scriptDir & "\Software\" & $fileName & '" ' & $switch)
        Else
            $switch = IniRead($iniFile, $fileName, "Switch", "/S")
            ;==?MsgBox(0, "", "Variable $switch contains " & $switch)
            RunWait('"' & $scriptDir & "\Software\" & $fileName & '"' & " " & $switch) ; For EXE installers
            If @error Then MsgBox(0, "exe type installation", '"' & $scriptDir & "\Software\" & $fileName & '" ' & $switch)
        EndIf
        ProgressSet($i / (UBound($sArray) - 1) * 100, Round($i / (UBound($sArray) - 1) * 100, 0) & "%", "Installing " & $i & " of " & UBound($sArray) - 1)
    Next
    Sleep(1000)
    ProgressOff()
EndFunc   ;==>_InstallSelectedSoftware

Func _UnselectAll()
    Local $count, $i
    ; Not Local $ListView1
    $count = _GUICtrlListView_GetItemCount($ListView1)
    For $i = 1 To $count Step 1
        _GUICtrlListView_SetItemChecked($ListView1, $i - 1, False)
    Next
EndFunc   ;==>_UnselectAll

Func _HelpTopics()
    Local $Form2, $Label1, $nMsg
    $Form2 = GUICreate("Help Topics", 633, 447)
    $Label1 = GUICtrlCreateLabel("", 8, 16, 612, 425)
    GUICtrlSetData(-1, "This program uses silent switches to install software without user interaction. To use this functionality, you can edit the Config.ini file to add software and their switches. Example: " & @CRLF & @CRLF & "[MetalScrollSetup_1.0.11.exe]" & @CRLF & "Switch=/S" & @CRLF & "Desc=A Meta Scroll Setup" & @CRLF & "Category=1" & @CRLF & @CRLF & "The name of the file is the first line in the brackets. The line with Switch= is the section for the unattended switch. The Desc= is the description for the program. The Category= is the tab you want the program to show up on the interface." & @CRLF & @CRLF & "Here are some common switches for various installers:" & @CRLF & @CRLF & "/silent used for Inno Setup installers" & @CRLF & "/verysilent used for Inno Setup installers" & @CRLF & "/S used for Nullsoft (aka NSIS) installers" & @CRLF & "/s used for Wise installers" & @CRLF & "-s used for Ghost installers" & @CRLF & "-ms used for Mozilla installers" & @CRLF & "/quiet used for Microsoft installers" & @CRLF & "/qb used for Microsoft installers" & @CRLF & "/qn used for Microsoft installers" & @CRLF & "/passive used for Microsoft installers" & @CRLF & "/Q used for Microsoft installers" & @CRLF & @CRLF & "Note: Some installers are case sensitive (Ghost and Nullsoft for sure).")
    GUISetState(@SW_SHOW)

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                GUIDelete($Form2)
                ExitLoop
        EndSwitch
    WEnd
EndFunc   ;==>_HelpTopics

Func _AboutProject()
    Local $Form3, $Label1a, $Label2a, $aboutData, $sData, $string, $nMsg
    ; Not Local $Form1
    $Form3 = GUICreate("About", 413, 196)
    $Label1a = GUICtrlCreateLabel("", 24, 64, 364, 113)
    $Label2a = GUICtrlCreateLabel("Software Installer 1.0", 24, 8, 375, 41)
    GUICtrlSetFont(-1, 24, 800, 2, "MS Sans Serif")
    GUICtrlSetColor(-1, 0x000080)
    GUISetState(@SW_SHOW)
    $aboutData = "This program was written|in a programming language called Autoit||Brought to you by abberration"
    $sData = StringSplit($aboutData, "|", 2)
    $string = ""
    For $i = 1 To UBound($sData) -1
        $string &= @CRLF & $sData[$i - 1] & @CRLF
        GUICtrlSetData($Label1a, $string)
        Sleep(1000)
    Next

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                GUIDelete($Form3)
                ExitLoop
        EndSwitch
    WEnd
 EndFunc   ;==>_AboutProject

You may need to add the subfolder path to the ini file. So it would be like [subfolderfilename.exe].

Edit1: Put incorrect variable $s2 in FileClose. Replaced with $subf

Edit2: $f also was not being closed with FileClose. Script seems to need a cleanup and variables renamed to something more meaningful. Line 151 goes to column 1302 in my editor which would be better with line continuations. I may do some changes later which may make it look quite different and submit it to abberration for review.

Edited by MHz

Share this post


Link to post
Share on other sites
Tulip

Thanks MHz for your help. the script is working very well by adding subfolders..

About installing in specific directories and installer types, I browsed through the link and understood that sendtoa3x is used for self extraction of exe files.

And also read about switches and installer types at http://unattended.sourceforge.net/installers.php . there are different switches for each installer type. now I have Setup.exe where I am giving the switch as /S and windows installer as /qn. which is installing in the default directory with out user interaction.

I can give swtichs in config.ini file like below, so that based on switches it take either User interaction installation or Unattended installation

[MetalMetalScrollSetup_1.0.11.exe]
Switch=/S
Desc=Meta scroll Setup
Category=1

[sonicSonicFileFinder2.3.msi]
Switch=/qb
Desc=File Finder
Category=1

[TotalCommandertcm801x64.exe]
Switch=/r
Desc=TotalCommander
Category=1

[xmlPadxmlpadsetup.exe]
Switch=/r
Desc=XMLPad
Category=1

 

I have other types of installers(.exe) , where I am able to identify one of them as InstallShield however unable to identify the installer type of other .exe file.

As per the link http://unattended.sourceforge.net/installers.php  , tried with /silent , /s , /r none of the switches are working for unattended software installation..

now question is

1) how to identify type of installer

2) if so what switch should be used for unattended installation for the same

3) how to specify destination directory if it is a unattended installation.( by default it installs in C:programfile(x86) )

Share this post


Link to post
Share on other sites
MHz

SendToA3X has many things in it. One is Identify Installer which when you right click on an installer, then use SendTo -> "File - Identify Installer" then it will be analyzed by PEiD.exe and will be recognized from that information. It may recognize most installers and the few that are not is what you will need to search for. Identify Installer does many things that relate to installers e.g. unpack them, install them with switches, copy to clipboard with the switches etc.

As stated in post #9, each type of installer has switches that relate to that installer type. Some have a install directory switch and some may not.

One of the templates from which SendToA3X reads from on a Nulsoft installer (NSIS) is

Nullsoft ® Installer (NSIS)

setup.exe /Option

(ALL SWITCHES MUST BE UPPER CASE)

Install Options
    /D=x:\dirname
        Install program to path. (NO DOUBLE QUOTES)
    /NCRC
        Skip CRC check.
Display Options
    /S
        Silent mode.
Comments
    AutoIt Usage
        Create the Au3 template script.
        Edit any variables at the start of the script, and add shortcuts, that require deletion.
        Refer to the help file. It displays sample highlighted items, to edit.
        Compile the script, into an exe, and keep it with the installer.
        Run the compiled exe, to install.
    Command line Usage
        To silently install, use the switch:
        Setup.exe /S

And shows you this in a window.

So you could use the below to install to a custom directory.

setup.exe /S /D=D:\Tool\Common

I am reasonably sure that NSIS reads the command as raw so double quotes may not be needed. Others may require double quotes around parameters with spaces.

Share this post


Link to post
Share on other sites
Tulip

Now I understood the usage of SendToA3X. and able to get the type of the installer for some.  

Modified the code according to that ..

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.8.1
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here

#RequireAdmin

#include <GUIConstants.au3>
#include <GuiListView.au3>
#include <Array.au3>
#include <File.au3>

Global $iniFile = @ScriptDir & "\ConfigSub.ini"
Global $scriptDir = @ScriptDir
; Main GUI
$Form1 = GUICreate("Software Installer", 633, 451)

$Tab1 = GUICtrlCreateTab(16, 8, 601, 377)
$TabSheet1 = GUICtrlCreateTabItem("Software Tools")
$ListView1 = GUICtrlCreateListView("Software Name|Description", 24, 40, 582, 334)
_GUICtrlListView_SetExtendedListViewStyle($ListView1, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES, $LVS_EX_GRIDLINES))
GUICtrlSendMsg(-1, 0x101E, 0, 200)
GUICtrlSendMsg(-1, 0x101E, 1, 375)

GUICtrlCreateTabItem("") ; This ends the tab item creation
$Button1 = GUICtrlCreateButton("Install Selected Software", 398, 395, 219, 25, 0)
$MenuItem1 = GUICtrlCreateMenu("File")
$MenuItem2 = GUICtrlCreateMenuItem("Unselect All", $MenuItem1)
$MenuItem3 = GUICtrlCreateMenuItem("Exit", $MenuItem1)
$MenuItem4 = GUICtrlCreateMenu("Help")
$MenuItem5 = GUICtrlCreateMenuItem("Help Topics", $MenuItem4)
$MenuItem6 = GUICtrlCreateMenuItem("About", $MenuItem4)
_Populate()
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            _InstallSelectedSoftware()
            WinActivate($Form1)
        Case $MenuItem2
            _UnselectAll()
        Case $MenuItem3
            Exit
        Case $MenuItem5
            _HelpTopics()
        Case $MenuItem6
            _AboutProject()
    EndSwitch
WEnd

Func _Populate()
    ; Find all files in the Software folder and populate the tabs with the installers.
    Local $array[1], $f, $i, $s, $category, $desc, $s2
    ; Not Local $scriptDir, $iniFile, $ListView1
    $i = -1
    $f = FileFindFirstFile($scriptDir & "\Software\*.*")
    If $f = -1 Then Return SetError(1, 0, 0)
    While 1
        $s = FileFindNextFile($f)
        If @error Then ExitLoop
        If @extended Then
            $subf = FileFindFirstFile($scriptDir & "\Software\" & $s & '\*')
            If $subf <> -1 Then
                While 1
                    $s2 = FileFindNextFile($subf)
                    If @error Then ExitLoop
                    If @extended Then ContinueLoop
                    Switch StringRight($s2, 4)
                        Case '.exe', '.msi'
                            $i += 1
                            ReDim $array[$i + 1]
                            $array[$i] = $s & '\' & $s2
                            ConsoleWrite($array[$i] & @CRLF)
                    EndSwitch
                WEnd
                FileClose($subf)
            EndIf
        EndIf
        If @extended Then ContinueLoop; as want no folders
        Switch StringRight($s, 4)
            Case '.exe', '.msi'
                $i += 1
                ReDim $array[$i + 1]
                $array[$i] = $s
        EndSwitch
    WEnd
    
    For $i = 0 To UBound($array) -1
        $category = IniRead($iniFile, $array[$i], "Category", "1")
        $desc = IniRead($iniFile, $array[$i], "Desc", FileGetVersion($scriptDir & "\Software\" & $array[$i], 'ProductName'))
        If $category == "1" Then
            GUICtrlCreateListViewItem($array[$i] & "|" & $desc, $ListView1)
        EndIf
    Next
EndFunc   ;==>_Populate

Func _InstallSelectedSoftware()
    Local $sArray[1], $count, $aCount, $fileName, $switch, $extension, $i, $type, $dir
    ; Not Local $ListView1, $iniFile, $scriptDir
    
    MsgBox(0, "_InstallSelectedSoftware", "Entering function!")

   ; Find which items were selected by user on Software Tools tab
    $count = _GUICtrlListView_GetItemCount($ListView1)
    $aCount = 0
    For $i = 1 To $count Step 1
        If _GUICtrlListView_GetItemChecked($ListView1, $i - 1) = True Then
            $sArray[$aCount] = _GUICtrlListView_GetItemText($ListView1, $i - 1)
            ReDim $sArray[UBound($sArray) + 1]
            $aCount += 1
        EndIf
    Next

    ; Begin installing selected software
    ProgressOn("Software Installer", "Installing", "", -1, -1, 16)
    For $i = 1 To UBound($sArray) - 1
        $fileName = $sArray[$i - 1]
        $dir = StringLeft($fileName, 5)
        $type = IniRead($iniFile, $fileName, "Type", "Inno")
        if $type = "NSIS" Then
           $switch = IniRead($iniFile, $fileName, "Switch", "/S")
           MsgBox(0, "", "Variable $switch contains " & $switch)
           Run("md D:\Test\" & $dir) 
           RunWait('"' & $scriptDir & "\Software\" & $fileName & '"' & " " & $switch & " " & "/D=D:\Test\" & $dir) ;
        ElseIf $type = "MSI" Then    
           $switch = IniRead($iniFile, $fileName, "Switch", "/qn")
           MsgBox(0, "", "Variable $switch contains " & $switch)
           Run("msiexec /i " & '"' & $scriptDir & "\Software\" & $fileName & '" ' & $switch)
        ElseIf $type = "InstallShield" Then    
           $switch = IniRead($iniFile, $fileName, "Switch", "/qn")
           MsgBox(0, "", "Variable $switch contains " & $switch)
           RunWait('"' & $scriptDir & "\Software\" & $fileName & '"' & " " & "/s" & " " & "/v" & " " & $switch)
        Else   
             $switch = IniRead($iniFile, $fileName, "Switch", "/S")
             MsgBox(0, "", "Variable $switch contains " & $switch)
             RunWait('"' & $scriptDir & "\Software\" & $fileName & '"' & " " & $switch)
        EndIf   
       ProgressSet($i / (UBound($sArray) - 1) * 100, Round($i / (UBound($sArray) - 1) * 100, 0) & "%", "Installing " & $i & " of " & UBound($sArray) - 1)
    Next
    Sleep(1000)
    ProgressOff()
EndFunc   ;==>_InstallSelectedSoftware

Func _UnselectAll()
    Local $count, $i
    ; Not Local $ListView1
    $count = _GUICtrlListView_GetItemCount($ListView1)
    For $i = 1 To $count Step 1
        _GUICtrlListView_SetItemChecked($ListView1, $i - 1, False)
    Next

EndFunc   ;==>_UnselectAll

Func _HelpTopics()
    Local $Form2, $Label1, $nMsg
    $Form2 = GUICreate("Help Topics", 633, 447)
    $Label1 = GUICtrlCreateLabel("", 8, 16, 612, 425)
    GUICtrlSetData(-1, "This program uses silent switches to install software without user interaction. To use this functionality, you can edit the Config.ini file to add software and their switches. Example: " & @CRLF & @CRLF & "[MetalScrollSetup_1.0.11.exe]" & @CRLF & "Switch=/S" & @CRLF & "Desc=A Meta Scroll Setup" & @CRLF & "Category=1" & @CRLF & @CRLF & "The name of the file is the first line in the brackets. The line with Switch= is the section for the unattended switch. The Desc= is the description for the program. The Category= is the tab you want the program to show up on the interface." & @CRLF & @CRLF & "Here are some common switches for various installers:" & @CRLF & @CRLF & "/silent used for Inno Setup installers" & @CRLF & "/verysilent used for Inno Setup installers" & @CRLF & "/S used for Nullsoft (aka NSIS) installers" & @CRLF & "/s used for Wise installers" & @CRLF & "-s used for Ghost installers" & @CRLF & "-ms used for Mozilla installers" & @CRLF & "/quiet used for Microsoft installers" & @CRLF & "/qb used for Microsoft installers" & @CRLF & "/qn used for Microsoft installers" & @CRLF & "/passive used for Microsoft installers" & @CRLF & "/Q used for Microsoft installers" & @CRLF & @CRLF & "Note: Some installers are case sensitive (Ghost and Nullsoft for sure).")
    GUISetState(@SW_SHOW)

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                GUIDelete($Form2)
                ExitLoop
        EndSwitch
    WEnd
EndFunc   ;==>_HelpTopics

Func _AboutProject()
    Local $Form3, $Label1a, $Label2a, $aboutData, $sData, $string, $nMsg
    ; Not Local $Form1
    $Form3 = GUICreate("About", 413, 196)
    $Label1a = GUICtrlCreateLabel("", 24, 64, 364, 113)
    $Label2a = GUICtrlCreateLabel("Software Installer 1.0", 24, 8, 375, 41)
    GUICtrlSetFont(-1, 24, 800, 2, "MS Sans Serif")
    GUICtrlSetColor(-1, 0x000080)
    GUISetState(@SW_SHOW)
    $aboutData = "This program was written|in a programming language called Autoit||Brought to you by abberration"
    $sData = StringSplit($aboutData, "|", 2)
    $string = ""
    For $i = 1 To UBound($sData) -1
        $string &= @CRLF & $sData[$i - 1] & @CRLF
        GUICtrlSetData($Label1a, $string)
        Sleep(1000)
    Next

    While 1
        $nMsg = GUIGetMsg()
        Switch $nMsg
            Case $GUI_EVENT_CLOSE
                GUIDelete($Form3)
                ExitLoop
        EndSwitch
    WEnd
 EndFunc   ;==>_AboutProject

config.ini

[Metal\MetalScrollSetup_1.0.11.exe]
Switch=/S
Desc=Meta scroll Setup
Category=1
Type=NSIS

[Sonic\SonicFileFinder2.3.msi]
Switch=/qb
Desc=File Finder
Category=1
Type=MSI

[TotalCommander\tcm801x64.exe]
Switch=/r
Desc=TotalCommander
Category=1

[XMLPad\xmlpadsetup.exe]
Switch=/qn
Desc=XMLPad
Category=1
Type=InstallShield

for NSIS type, able to install in the custom directory. however I could not the find the way to install in custom directory for other installer types.

For Installshield , i could not do unattended installation (silent) by executing like this  setup.exe /s /v"/qn" where it says Command line Usage
  To silently install, use:
   setup.exe /s /v"/qn"
  To silently install, if installer extracted, then use:
  setup.msi /qn

Please let meknow whether this holds good , Do I have to handle any other errors. I have not covered all the installer types..

still looking for the ways to install in custom directory for other installer types(msi,Installshield)

Edited by Tulip

Share this post


Link to post
Share on other sites
MHz

Very creative on the script changes of adding Type. :thumbsup:

Installshield is not one of my favorites. The creators of these may disable switches in them so you may need to automate or repack them. There are a couple of Installshield types to note which is one is all executable while the other is a msi wrapped in an executable. Both of the commands below I have used with some success.

The exe one is

PackageName.exe /s /a /s /sms /f1"c:\windows\ProgramName.iss" /f2"c:\ProgramName.log"

while the msi wrapped exe is

setup.exe /s /v"/qn"

Many of the later versions of InstallShield would be the later command.

MSI uses property settings to influence things like install directory and such. So you can search for the properties for that installer or some tools may exist to look into the MSI (which is a database file) to find available properties to use.

If you want them all to a certain directory then you may need to repack them.

Share this post


Link to post
Share on other sites
Tulip

ok.. Thanks MHz. u made me to understand the AutoIt script in short time.

will look for the options for custom directory for other types...

Will update you for further enhancements to the script..

Share this post


Link to post
Share on other sites
MHz

I had a look at >Software Installer by abberration. Looks like you did quite a bit of hacking of the code before introducing me to this modified version. That is OK.

This was based on your last script. I did some cleaning up of variable names. Reset $inifile to use Config.ini as mentioned in the help window. Changed $scriptDir to $rootDir so it is the path to the root of the software folder. Disable install button while installing. Added some more installer Types. Changed the way switches are set and added InstallDir for installers that may support it. Added information to Help Topics window. Added modified by ... to the About window. I am a default single quoter so I changed quotes in the script to suit and use double quotes when I use them to include as part of a string. Various other little things may have done.

#RequireAdmin

#include <GUIConstants.au3>
#include <GuiListView.au3>
#include <Array.au3>
#include <File.au3>

; configuration settings file
Global $iniFile = @ScriptDir & '\Config.ini'
; root path to find and run files from
Global $rootDir = @ScriptDir & '\Software'

; Main GUI
$Form1 = GUICreate("Software Installer", 633, 451)

$Tab1 = GUICtrlCreateTab(16, 8, 601, 377)
$TabSheet1 = GUICtrlCreateTabItem("Software Tools")
$ListView1 = GUICtrlCreateListView("Software Name|Description", 24, 40, 582, 334)
_GUICtrlListView_SetExtendedListViewStyle($ListView1, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_CHECKBOXES, $LVS_EX_GRIDLINES))
GUICtrlSendMsg(-1, 0x101E, 0, 200)
GUICtrlSendMsg(-1, 0x101E, 1, 375)

GUICtrlCreateTabItem("") ; This ends the tab item creation
$Button1 = GUICtrlCreateButton("Install Selected Software", 398, 395, 219, 25, 0)
$MenuItem1 = GUICtrlCreateMenu("File")
$MenuItem2 = GUICtrlCreateMenuItem("Unselect All", $MenuItem1)
$MenuItem3 = GUICtrlCreateMenuItem("Exit", $MenuItem1)
$MenuItem4 = GUICtrlCreateMenu("Help")
$MenuItem5 = GUICtrlCreateMenuItem("Help Topics", $MenuItem4)
$MenuItem6 = GUICtrlCreateMenuItem("About", $MenuItem4)
_Populate()
GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            GUICtrlSetState($Button1, $GUI_DISABLE)
            _InstallSelectedSoftware()
            GUICtrlSetState($Button1, $GUI_ENABLE)
            WinActivate($Form1)
        Case $MenuItem2
            _UnselectAll()
        Case $MenuItem3
            Exit
        Case $MenuItem5
            _HelpTopics()
        Case $MenuItem6
            _AboutProject()
    EndSwitch
WEnd

Func _Populate()
    ; Find all files in the root folder and populate the tabs with the installers.
    Local $aPaths[1], $hFind[2], $sFound[2], $1
    ; Not Local $rootDir, $iniFile, $ListView1
    $1 = -1
    ; open a handle to find files and folders in the folder set
    $hFind[0] = FileFindFirstFile($rootDir & '\*.*')
    ; if not a valid handle then return with error
    If $hFind[0] = -1 Then Return SetError(1, 0, 0)
    While 1
        ; get the file or folder name
        $sFound[0] = FileFindNextFile($hFind[0])
        If @error Then ExitLoop
        If @extended Then
            ; open a handle in the subfolder to find files
            $hFind[1] = FileFindFirstFile($rootDir & '\' & $sFound[0] & '\*')
            If $hFind[1] <> -1 Then
                While 1
                    $sFound[1] = FileFindNextFile($hFind[1])
                    If @error Then ExitLoop
                    If @extended Then ContinueLoop
                    ; collect only these file types and adjust size of the paths array
                    Switch StringRight($sFound[1], 4)
                        Case '.exe', '.msi'
                            $1 += 1
                            ReDim $aPaths[$1 + 1]
                            $aPaths[$1] = $sFound[0] & '\' & $sFound[1]
                    EndSwitch
                WEnd
                ; close the search handle
                FileClose($hFind[1])
            EndIf
        Else
            ; collect files in the root folder that was set above
            Switch StringRight($sFound[0], 4)
                Case '.exe', '.msi'
                    $1 += 1
                    ReDim $aPaths[$1 + 1]
                    $aPaths[$1] = $sFound[0]
            EndSwitch
        EndIf
    WEnd
    FileClose($hFind[0])
    ;
    For $1 = 0 To UBound($aPaths) -1
        ; if Category is 1 then list filename|description in the listwiev ctrl
        If IniRead($iniFile, $aPaths[$1], 'Category', '1') == '1' Then
            GUICtrlCreateListViewItem( _
                $aPaths[$1] & "|" & _
                IniRead($iniFile, $aPaths[$1], 'Desc', FileGetVersion($rootDir & '\' & $aPaths[$1], 'ProductName')), _
                $ListView1 _
            ); Software Name|Description
        EndIf
    Next
EndFunc   ;==>_Populate

Func _InstallSelectedSoftware()
    Local $aSelected[1], $1, $2, $sCommand, $iItemCount, $sFileName, $sInstallDir, $sSwitch, $sWorkingDir
    ; Not Local $ListView1, $iniFile, $rootDir
    ; Find which items were selected by user on Software Tools tab
    $iItemCount = _GUICtrlListView_GetItemCount($ListView1)
    ; use a counter variable for the array index when calling _GUICtrlListView_GetItemText
    $2 = 0
    For $1 = 1 To $iItemCount
        If _GUICtrlListView_GetItemChecked($ListView1, $1 - 1) = True Then
            ; get the checked items from the listview
            $aSelected[$2] = _GUICtrlListView_GetItemText($ListView1, $1 - 1)
            ReDim $aSelected[UBound($aSelected) + 1]
            $2 += 1
        EndIf
    Next
    ; Begin installing selected software
    ProgressOn('Software Installer', 'Installing', '', -1, -1, 16)
    For $1 = 1 To UBound($aSelected) -1
        $sFileName = $aSelected[$1 - 1]
        ;
        $sInstallDir = IniRead($iniFile, $sFileName, 'InstallDir', '')
        $sSwitch = IniRead($iniFile, $sFileName, 'Switch', '')
        ; set switched based on type of installer read from the inifile
        Switch IniRead($iniFile, $sFileName, 'Type', '')
            Case 'Ghost'
                If $sSwitch == '' Then $sSwitch = '/s'
            Case 'InnoSetup'
                If $sSwitch == '' Then $sSwitch = '/-sp /verysilent /suppressmsgboxes /norestart'
                If $sInstallDir Then $sSwitch &= ' /dir="' & $sInstallDir & '"'
            Case 'InstallShield', 'InstallShield(new)'
                If $sSwitch == '' Then
                    $sSwitch = '/s /v"/qn"'
                    If StringRight($sFileName, 4) = '.msi' Then
                        $sSwitch = '/qn'
                    EndIf
                Else
                    $sSwitch = '/s /v"' & $sSwitch & '"'
                EndIf
            Case 'InstallShield(old)'
                If $sSwitch == '' Then $sSwitch = '/s /a /s /sms'
            Case 'MSI'
                If $sSwitch == '' Then $sSwitch = '/qn'
            Case 'NSIS'
                If $sSwitch == '' Then $sSwitch = '/S'
                If $sInstallDir Then $sSwitch &= ' /D=' & $sInstallDir
            Case 'Tarma'
                If $sSwitch == '' Then $sSwitch = '/q2 /b0'
                If $sInstallDir Then $sSwitch &= ' /install:"' & $sInstallDir & '"'
            Case 'VISE'
                If $sSwitch == '' Then $sSwitch = '-s'
                If $sInstallDir Then $sSwitch &= ' -t "' & $sInstallDir & '"'
            Case 'WinZip'
                If $sSwitch == '' Then $sSwitch = '/autoinstall'
            Case Else
                If $sSwitch == '' Then
                    Switch StringRight($sFileName, 4)
                        Case '.msi'
                            $sSwitch = '/qn'
                        Case '.exe'
                            $sSwitch = '/S'
                    EndSwitch
                EndIf
        EndSwitch
        ; working directory to where the file is
        $sWorkingDir = $rootDir
        If StringInStr($sFileName, '\') Then
            $sWorkingDir &= '\' & StringLeft($sFileName, StringInStr($sFileName, '\', 0, -1))
        EndIf
        ; install command
        $sCommand = '"' & $rootDir & '\' & $sFileName & '" ' & $sSwitch
        ; prepend to install command if is an msi file
        If StringRight($sFileName, 4) = '.msi' Then $sCommand = 'msiexec /i ' & $sCommand
        ; run the installer
        RunWait($sCommand, $sWorkingDir)
        ;
        ProgressSet($1 / (UBound($aSelected) - 1) * 100, Round($1 / (UBound($aSelected) - 1) * 100, 0) & '%', 'Installing ' & $1 & ' of ' & UBound($aSelected) - 1)
    Next
    Sleep(1000)
    ProgressOff()
EndFunc   ;==>_InstallSelectedSoftware

Func _UnselectAll()
    Local $count, $1
    ; Not Local $ListView1
    $count = _GUICtrlListView_GetItemCount($ListView1)
    For $1 = 1 To $count Step 1
        _GUICtrlListView_SetItemChecked($ListView1, $1 - 1, False)
    Next

EndFunc   ;==>_UnselectAll

Func _HelpTopics()
    Local $Form2, $Label1
    $Form2 = GUICreate('Help Topics', 633, 447)
    $Label1 = GUICtrlCreateLabel('', 8, 16, 612, 425)
    GUICtrlSetData(-1, 'This program uses silent switches to install software without user interaction. ' & _
        'To use this functionality, you can edit the Config.ini file to add software and their switches. ' & _
        'Example: ' & @CRLF & @CRLF & _
        '[MetalScrollSetup_1.0.11.exe]' & @CRLF & _
        'Desc=A Meta Scroll Setup' & @CRLF & _
        'Switch=/S' & @CRLF & _
        'Type=NSIS' & @CRLF & _
        'InstallDir=C:\Program Files\My Program' & @CRLF & _
        'Category=1' & @CRLF & @CRLF & _
        'The name of the file is the first line in the brackets. The line with ' & _
        'Switch= is the section for the unattended switch. ' & _
        'Type= can be one of these which can set a default switch if Switch= is not set: ' & _
        'Ghost, InnoSetup, InstallShield or InstallShield(new), InstallShield(old), MSI, NSIS, Tarma, VISE, WinZip. ' & _
        'InstallDir= is a full path to the install directory and supports Type= InnoSetup, NSIS, Tarma, VISE. ' & _
        'The Desc= is the description for the program. ' & _
        'The Category= is the tab you want the program to show up on the interface.' & @CRLF & @CRLF & _
        'Here are some common switches for various installers:' & @CRLF & @CRLF & '/silent used for Inno Setup installers' & @CRLF & _
        '/verysilent used for Inno Setup installers' & @CRLF & '/S used for Nullsoft (aka NSIS) installers' & @CRLF & _
        '/s used for Wise installers' & @CRLF & '-s used for Ghost installers' & @CRLF & '-ms used for Mozilla installers' & @CRLF & _
        '/quiet used for Microsoft installers' & @CRLF & '/qb used for Microsoft installers' & @CRLF & _
        '/qn used for Microsoft installers' & @CRLF & '/passive used for Microsoft installers' & @CRLF & _
        '/Q used for Microsoft installers' & @CRLF & @CRLF & 'Note: Some installers are case sensitive (Ghost and Nullsoft for sure).' _
    )
    GUISetState(@SW_SHOW)
    ;
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                GUIDelete($Form2)
                ExitLoop
        EndSwitch
    WEnd
EndFunc   ;==>_HelpTopics

Func _AboutProject()
    Local $Form3, $Label1a, $Label2a, $sAboutData, $sData, $sString
    ; Not Local $Form1
    GUISetState(@SW_DISABLE, $Form1)
    $Form3 = GUICreate('About', 413, 196, Default, Default, Default, Default, $Form1)
    $Label1a = GUICtrlCreateLabel('', 24, 64, 364, 113+0)
    $Label2a = GUICtrlCreateLabel('Software Installer 1.0', 24, 8, 375, 41)
    GUICtrlSetFont(-1, 24, 800, 2, 'MS Sans Serif')
    GUICtrlSetColor(-1, 0x000080)
    GUISetState(@SW_SHOW)
    $sAboutData = 'This program was written|in a programming language called Autoit||Brought to you by abberration. Modified by MHz and Tulip'
    ;
    $sData = StringSplit($sAboutData, '|', 2)
    For $1 = 0 To UBound($sData) -1
        $sString &= @CRLF & $sData[$1] & @CRLF
        GUICtrlSetData($Label1a, $sString)
        Sleep(500)
    Next
    ;
    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                GUIDelete($Form3)
                GUISetState(@SW_ENABLE, $Form1)
                WinActivate($Form1)
                ExitLoop
        EndSwitch
    WEnd
EndFunc   ;==>_AboutProject

May need a rigorous testing to sort any issues that may exist. :)

Edit: Seems I can not spell category correct. fixed.

Edited by MHz

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
Sign in to follow this  

×