Jump to content
Sign in to follow this  
DemonAngel

Unattend

Recommended Posts

Usage.

To create ini files. unattend.au3

To install using a ini file. unattend.au3 inifilename.ini

I hope it is usefull. If anyone has some improvement ideas please share.

#include <GuiConstants.au3>
#Include <GuiList.au3>

Global $Setupfile
Global $Counter = "0"
Global $Inifile = ""
Global $text,$title,$List_1,$winlistgui
$temp = ""

If $cmdline[0] <> "0" Then
    InstSoft($cmdline[1])
EndIf
    
$maingui = GuiCreate("Unattend Installation Creator", 232, 90,1, 1); , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS))

$Input_setup = GuiCtrlCreateInput($temp, 110, 10, 110, 20)
$Button_START = GuiCtrlCreateButton("Setup EXE Name:", 10, 10, 90, 20)
$Button_ADDFUNC = GuiCtrlCreateButton("Add Funtion", 10, 40, 210, 20)
$Button_EXIT = GuiCtrlCreateButton("Close and EXIT", 10, 65, 210, 20)

GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $Input_setup
        If GUICtrlRead($Input_setup) = "" Then  
            GUICtrlSetData($Button_START,"Setup EXE Name:")
        Else
            GUICtrlSetData($Button_START,"START SETUP") 
        EndIf
    Case $msg = $Button_START
        StartEXE()
    Case $msg = $Button_ADDFUNC
        Addfunc()   
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case $msg = $Button_EXIT
        ExitLoop
    Case Else
    ;;;
    EndSelect
WEnd
Exit

Func Addfunc()
    If $Inifile = "" Then
        $Inifile = InputBox("Unattend Ini Information","Please type a name for this installation ini file.")
        if @error Then Return
        $inifile = FileGetShortName(@ScriptDir&"\"&$inifile&".ini")
        IniWrite($Inifile,"SETUP","SETUPEXE",GUICtrlRead($Input_setup))
    EndIf   
$var = WinList()

$winlistgui = GuiCreate("Window List", 281, 336,-1, -1)
$List_1 = GuiCtrlCreateList("Window List", 10, 40, 260, 266)
$Label_2 = GuiCtrlCreateLabel("Select the correct Window", 10, 10, 150, 20)
$button_winselect = GUICtrlCreateButton("OK",100,300,80)
GuiSetState()

For $i = 1 to $var[0][0]
  If $var[$i][0] <> "" AND IsVisible($var[$i][1]) Then
   GUICtrlSetData($List_1,$var[$i][0])
  EndIf
Next


While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        GUIDelete($winlistgui)  
        ExitLoop
    Case $msg = $List_1
        
    Case $msg = $button_winselect
        $Counter = $Counter + "1"
        $title = GUICtrlRead($List_1)
        $text = WinGetText($title)
        $text = StringLeft($text,"5")
        IniWrite($Inifile,"SETUP","Counter",$Counter)
        IniWrite($Inifile,"WININFO","Title"&$Counter,$title)
        IniWrite($Inifile,"WININFO","Text"&$Counter,$text)
        Poplist()
        ExitLoop
    Case Else
    ;;;
    EndSelect
WEnd
EndFunc

Func poplist()
    GUIDelete($winlistgui)
    $Controllistgui = GuiCreate($title&" Control List", 281, 336,-1, -1)
    $List_2 = GuiCtrlCreateList("Control List", 10, 40, 260, 266)
    $Label_3 = GuiCtrlCreateLabel("Select the correct Window", 10, 10, 150, 20)
    $button_Controlselect = GUICtrlCreateButton("OK",100,300,80)
    GuiSetState()
    
    for $CCnt = 1 to 99 Step 1
        $tmpRead = ControlGetText($title,$text,"Button"&$CCnt)
        If $tmpRead = "" then
            If $CCnt = "1" Then
                MsgBox(0,"Error","Unable to find any Controls")
                GUIDelete($Controllistgui)
                Return(0)
            EndIf
        ExitLoop
        EndIf   
        GUICtrlSetData($List_2,"Button"&$CCnt&"- "&$tmpRead)
    Next

        $msg = ""
        While 1
        $msg = GuiGetMsg()
        Select
        Case $msg = $GUI_EVENT_CLOSE
        GUIDelete($Controllistgui)  
        ExitLoop
        Case $msg = $button_Controlselect
        $button = GUICtrlRead($List_2)
        $button = StringLeft($button,(StringInStr($button,"-")-"1"))
        IniWrite($Inifile,"WININFO","button"&$Counter,$button)
        GUIDelete($Controllistgui)
        ExitLoop
        EndSelect
        WEnd

EndFunc

Func StartEXE()
    $setupfile = FileGetShortName(@ScriptDir&"\"&GUICtrlRead($Input_setup))
    If GUICtrlRead($Input_setup) = "" Then
        MsgBox(0,"Error","Filename Field Cannot be Blank")
    ElseIf not FileExists($setupfile) Then
        MsgBox(0,"Error","Setup File Not Found")
    Else
        If $Inifile = "" Then 
            $Inifile = InputBox("Information","Please type the name of the new ini file")
            $Inifile = FileGetShortName(@ScriptDir&"\"&$Inifile&".ini")
        EndIf
        IniWrite($Inifile,"SETUP","SETUPEXE",GUICtrlRead($Input_setup))
        Run($setupfile)
    EndIf   
EndFunc

Func InstSoft($inifile)
$timeout = "1"
    If Not FileExists(@ScriptDir&"\"&$inifile) Then
        MsgBox(0,"Error","The file specified was not found ... "&@ScriptDir&"\"&$inifile)
        Exit
    EndIf
$run = @ScriptDir&"\"&IniRead(@ScriptDir&"\"&$inifile,"SETUP","SETUPEXE","")
    If Not FileExists($run) Then
        MsgBox(0,"Error","The Setup file specified was not found ... "&$run)
        Exit
    EndIf
$maxcount = IniRead(@ScriptDir&"\"&$inifile,"SETUP","Counter","")

Run($run)
for $tmpcnt = "1" to $maxcount Step 1
    $title = IniRead(@ScriptDir&"\"&$inifile,"WININFO","Title"&$tmpcnt,"")
    $text = IniRead(@ScriptDir&"\"&$inifile,"WININFO","Text"&$tmpcnt,"")
    $button = IniRead(@ScriptDir&"\"&$inifile,"WININFO","button"&$tmpcnt,"")
    While 1
    $wincheck = WinExists($title,$text)
    If $wincheck = "1" Then
        Sleep(1500)
        ControlClick($title,$text,$button)
        ExitLoop
    Else
        Sleep(1000)
        $timeout = $timeout + "1"
        If $timeout = "120" Then
            WinClose($title,"")
            Exit
        EndIf   
    EndIf   
    WEnd
Next
Exit
EndFunc

Func IsVisible($handle)
  If BitAnd( WinGetState($handle), 2 ) Then 
    Return 1
  Else
    Return 0
  EndIf

EndFunc

Share this post


Link to post
Share on other sites

Basicly it launches a setup exe file and then looks for windows. If it finds a window it then clicks the button on that window that you specified. It can be used to do a unattended setup of just about any application.

If you run the script then it will launch a gui that you can use to create a unattend INI file. (Used to store information the script will need for the install) If you run the scritp with the ini filename in a command line then it will start to do the unattened install using the specified INI file. Example: compiledscript.exe winzip.ini

It can be used to script installs of software for multiple users using logon scripts. Something else I would suggest is using AutoIT to disable the keyboard and mouse input while the script is running.

I have to admit my code is a bit sloppy and may need some cleanup. :lmao:

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  

×
×
  • Create New...