Jump to content

Need Macro Generator Help


Grim107
 Share

Recommended Posts

Hi all. I'm new here, and have never done any scripting before. I'm wanting to use AutoIT for the simple purpose of creating unattended installers for a bunch of programs that I can include in the $OEM$ folder on a WinXP Pro CD. I know that this isn't a hard process, but I'm really having trouble. My problem arises every time I want to select/deselect components to install, startup behavior, etc. For the life of me, I can't figure out how to go about this.

Last night, I noticed the Macro Generator. I figured I'd be able to simply go through the install process and it would record it. Unfortunately, this doesn't seem to be the case. I'm still having problems ticking the boxes. I really don't know why. I'm including the script it generates for "Super F4" (a small, freeware utility). Can someone please tell me what is wrong, and how I can go about fixing it? I'd rather use the macro generator, but I'd be willing to code it if I have to. Thanks very much.

#region --- AutoIt Macro Generator V 0.21 beta ---
Opt("WinTitleMatchMode", 4)
WinWait("Installer Language","Please select a language.")
ControlClick("Installer Language","Please select a language.","Button1")
;AutoIt supports no SysTreeView32
WinWait("SuperF4 1.2 Setup ","< &Back")
ControlClick("SuperF4 1.2 Setup ","< &Back","SysTreeView321")
;AutoIt supports no SysTreeView32
ControlClick("SuperF4 1.2 Setup ","< &Back","SysTreeView321")
;AutoIt supports no SysTreeView32
ControlClick("SuperF4 1.2 Setup ","< &Back","SysTreeView321")
ControlClick("SuperF4 1.2 Setup ","< &Back","Button2")
ControlClick("SuperF4 1.2 Setup ","< &Back","Button2")
ControlCommand("SuperF4 1.2 Setup ","< &Back","Button4","UnCheck","")
ControlClick("SuperF4 1.2 Setup ","< &Back","Button2")
Link to comment
Share on other sites

Hi,

welcome to the forum.

I don't know what the exact problem is, but it looks like it is because the components list is a treeview (SysTreeView32), which doesn't seem to be supported by the macro generator judging by the comments in your sample.

;AutoIt supports no SysTreeView32

I might be wrong and someone might come along with a simpler solution, but I guess you are going to have to code at least part of the script.

There is a tutorial of how to install WinZip with AutoIt in the documentation, and here is a sample script to get you on your way with the checking/unchecking of the items.

#cs
    NOTE: This only works for treeview items and there child items, no deeper then that
#ce
; include the constants and UDF's we will need in this script
#include <GuiConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GuiTreeView.au3>
#include <Array.au3>
 
 
AutoItSetOption("WinTitleMatchMode", 4)
 
 
; this 2D array will hold the text labels of the items that need to be checked/unchecked
; the first item is the full label to match, the second a boolean True = check, False = uncheck
Global $aItems[4][2] = [["Check for update before installing", True], _
        ["Start Menu Shortcut", True], _
        ["AutoStart", True], _
        ["Hide tray", True]]
 
 
;~ _ArrayDisplay($aItems, "Treeview items to check/uncheck") ; display the array with items $aItems (this can be commented out)
 
Run(@ScriptDir & "\SuperF4-1.2.exe") ; run the installer executable (assumes the file is in the same directory as the script)
 
#Region --- AutoIt Macro Generator V 0.21 beta ---
WinWait("Installer Language", "Please select a language.")
ControlClick("Installer Language", "Please select a language.", "Button1")
WinWait("SuperF4 1.2 Setup ", "< &Back")
#EndRegion --- AutoIt Macro Generator V 0.21 beta ---
 
; this is where we insert our script to check/uncheck the treeview items
$hWin = WinGetHandle("SuperF4") ; get the handle of the installer window
$hTreeView = ControlGetHandle($hWin, "", "[CLASS:SysTreeView32; INSTANCE:1]") ; get the handle of the treeview
$fResult = _TV_CheckItemsByLabel($hTreeView, $aItems) ; check/uncheck items in the treeview
Switch @error ; output the result  (this Switch...EndSwitch can be commented out, just uncomment the If Not $fResult... line, a few lines down)
    Case 0 ; ; _TV_CheckItemsByLabel returned with @error 0, no errors
        MsgBox(262144, "Result", @extended & " items have been checked/unchecked")
    Case 1 ; _TV_CheckItemsByLabel returned with @error 1
        MsgBox(262192, "Warning", "$hTreeView is not a window handle")
    Case 2 ; _TV_CheckItemsByLabel returned with @error 2
        MsgBox(262192, "Warning", "TreeView has no items")
EndSwitch
;~ If Not $fResult Then Exit 1 ; there was an error with _TV_CheckItemsByLabel, exit script with exitcode 1
 
#Region --- AutoIt Macro Generator V 0.21 beta ---
ControlClick("SuperF4 1.2 Setup ", "< &Back", "Button2") ; we are done here so go to next page
WinWait(" 1.2 Setup ", "&Install")
 
; insert the rest the installer script here
 
#EndRegion --- AutoIt Macro Generator V 0.21 beta ---
 
 
; Check/Uncheck treeview items if the labels match an item in the array $aItems
Func _TV_CheckItemsByLabel($hTreeView, ByRef $aItems)
    If Not IsHWnd($hTreeView) Then Return SetError(1, 0, False) ; invalid treeview handle
 
    Local $hItem = _GUICtrlTreeView_GetFirstItem($hTreeView) ; get the handle of the first item in the tree
    If Not $hItem Then Return SetError(2, 0, False) ; no first item = empty treeview
 
    Local $hChild, $sLabel, $iCounter = 0
    While 1
        ConsoleWrite("-> item = " & _GUICtrlTreeView_GetText($hTreeView, $hItem) & @CRLF) ; just for debugging (this can be commented out)
        __CheckCheck($hTreeView, $hItem, $aItems, $iCounter) ; check if this item needs to be checked/unchecked
 
        $hChild = _GUICtrlTreeView_GetFirstChild($hTreeView, $hItem) ; get handle of first child of this item
        If $hChild Then ; we found a child
            While 1 ; loop over all child nodes to check if it needs to be checked
                $hItem = $hChild ; set the child as item, this is so _GUICtrlTreeView_GetNext will get the correct next item
                ConsoleWrite("->     child = " & _GUICtrlTreeView_GetText($hTreeView, $hChild) & @CRLF) ; just for debugging (this can be commented out)
                __CheckCheck($hTreeView, $hChild, $aItems, $iCounter) ; check if this child item needs to be checked/unchecked
 
                $hChild = _GUICtrlTreeView_GetNextChild($hTreeView, $hChild) ; get handle of the next child
                If Not $hChild Then ExitLoop ; no more children so exit this loop to continue with the next item
            WEnd
        EndIf
 
        $hItem = _GUICtrlTreeView_GetNext($hTreeView, $hItem) ; get handle of the next item in the tree
        If Not $hItem Then ExitLoop ; no more items so exit loop
    WEnd
 
    Return SetError(0, $iCounter, True)
EndFunc   ;==>_TV_CheckItemsByLabel
 
Func __CheckCheck($hTreeView, $hItem, ByRef $aItems, ByRef $iCounter)
    Local $sLabel = _GUICtrlTreeView_GetText($hTreeView, $hItem) ; get the label text of the treeview item
;~   ConsoleWrite("$sLabel = " & $sLabel & @CRLF)
    For $i = 0 To UBound($aItems) - 1 Step 1 ; loop over all items in the array with items to check
        If StringLower($sLabel) == StringLower($aItems[$i][0]) Then ; if the label is the same as this item in the array
            ConsoleWrite("  Label matched array item " & $i & ", check = " & $aItems[$i][1] & @CRLF) ; just for debugging (this can be commented out)
            $res = _GUICtrlTreeView_SetChecked($hTreeView, $hItem, $aItems[$i][1]) ; check/uncheck item
            $iCounter += 1 ; update counter
            Return True ; item matched so we return true
        EndIf
    Next
    Return False ; no item matched
EndFunc   ;==>__CheckCheck

The comments in the sample script should give you an idea of what is going on.

If you get stuck just post back here.

Edit: forgot to update item after looping over children ($hItem = $hChild)

Edited by Robjong
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...