Jump to content

Precedence of Funcs executing


Recommended Posts

How does AutoIt handle multiple functions when it comes to which one to execute?

I have a getProperties func and a func that creates a volume. I need to get the properties from a text file and plug those into certain variables in my volume func.

No matter how I seem to order the executions, the volume func always runs first, which is completely useless.

Could someone give me some guidance or general advice with whats going on here?

Many thanks.

Link to comment
Share on other sites

  • Moderators

cambradford.

Welcome to the AutoIt forum. :)

AutoIt runs functions in the order you call them. Please post the code you are using so we can see why this is apparently not happening in your case. When you post the code please use Code tags - see here how to do it. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Here is what I'm working with, thanks for the speedy reply :)

I want to run FileGetProperty to pull values from some text file that will go into my _TC_Container_Create to replace the variables that are hard-coded in. I think that shouldn't be too much of a pain, but for some reason my _TC_Container_Create() func will execute before the other.

#include <winapi.au3>
#include <Constants.au3>

AutoItSetOption("WinDetectHiddenText", 1)
Opt("WinTitleMatchMode", 3)
Global $PID_TC_Format = 0
ConsoleWrite("_FileGetProperty returned " & _FileGetProperty("") & @TAB & @error & @crlf)
ConsoleWrite("_TC_Container_Create("") returned " & _TC_Container_Create("") & @TAB & @error & @crlf)

#include <File.au3> ; only used for the example script, not needed for the UDF
#include <Array.au3> ; only used for the example script, not needed for the UDF
$sFolder = FileSelectFolder("Select a folder to scan", "")
$sFolder &= ""
$aFiles = _FileListToArray($sFolder)
For $I = 1 To $aFiles[0]
$aDetails = _FileGetProperty($sFolder & $aFiles[$I]) ; Returns an array with all properties of the file
_ArrayDisplay($aDetails)
ConsoleWrite("File size of " & $sFolder & $aFiles[$I] & " = " & _FileGetProperty($sFolder & $aFiles[$I], "size") & @CRLF) ; displays in the console the Size of the file
Next

Func _FileGetProperty($FGP_Path, Const $FGP_PROPERTY = "")
    $FGP_Path = StringRegExpReplace($FGP_Path, '"C:\Users\Cameron\volumes\readthis.txt', "") ; strip the quotes, if any from the incoming string
    If Not FileExists($FGP_Path) Then Return SetError(1, 0, "") ; path not found
    Local Const $objShell = ObjCreate("Shell.Application")
    If @error Then Return SetError(3, 0, "")
    Local $iPropertyCount = 300 ; arbitrary number used, Windows 7 only returns 288 properties, Windows XP only returns 38 (future proofing)
    Local Const $FGP_File = StringTrimLeft($FGP_Path, StringInStr($FGP_Path, "\", 0, -1))
    Local Const $FGP_Dir = StringTrimRight($FGP_Path, StringLen($FGP_File) + 1)
    Local Const $objFolder = $objShell.NameSpace($FGP_Dir)
    Local Const $objFolderItem = $objFolder.Parsename($FGP_File)
    Local $Return = "", $iError = 0
    If $FGP_PROPERTY Then
        For $I = 0 To $iPropertyCount
            If $objFolder.GetDetailsOf($objFolder.Items, $I) = $FGP_PROPERTY Then
                $Return = $objFolder.GetDetailsOf($objFolderItem, $I)
            EndIf
        Next
        If $Return = "" Then
            $iError = 2
        EndIf
    Else
        Local $av_ret[$iPropertyCount + 1][2] = [[0]]
        For $I = 1 To $iPropertyCount
            If $objFolder.GetDetailsOf($objFolder.Items, $I) Then
                $av_ret[$I][0] = $objFolder.GetDetailsOf($objFolder.Items, $I - 1)
                $av_ret[$I][1] = $objFolder.GetDetailsOf($objFolderItem, $I - 1)
                $av_ret[0][0] += 1
            EndIf
        Next
        ReDim $av_ret[$av_ret[0][0] + 1][2]
        If Not $av_ret[1][0] Then
            $iError = 2
            $av_ret = $Return
        Else
            $Return = $av_ret
        EndIf
    EndIf
    Return SetError($iError, 0, $Return)
EndFunc   ;==>_FileGetProperty

Func _TC_Container_Create($TC_Container_Location, $TC_Container_Encryption = "AES", $TC_Container_Hash = "RIPEMD-160", $TC_Container_Size_KB = 10000, $TC_Container_Password = "test", $TC_Container_Filesystem = "NTFS")

    Local $b_TC_Volume_Creation_Wizard_failed = False, $hWnd_TC_Volume_Creation_Wizard = 0, $TC_Volume_Creation_Wizard_Error_Code = 0

    ; NTFS min Size = 2829 KB
    ; FAT min Size = 275 KB
    ; ControlSetText() if it's just text you're sending. It's much faster.

    If Not $TC_Container_Location Then $TC_Container_Location = @ScriptDir & "\Test.tc"
    If $TC_Container_Size_KB < 275 Then $TC_Container_Size_KB = 275
    If $TC_Container_Size_KB < 2829 Then $TC_Container_Filesystem = "FAT"

    If FileExists($TC_Container_Location) Then
        If MsgBox(262420, "TCMyFiles", "The Target File" & @CRLF & @CRLF & $TC_Container_Location & @CRLF & @CRLF & "already exists. Do you want to overwrite the file?") <> 6 Then
            SetError(99)
            Return 0
        EndIf
        FileDelete($TC_Container_Location)
    Else
        $TC_Check_Location = FileOpen($TC_Container_Location,10)
        if $TC_Check_Location <> -1 then
            FileClose($TC_Check_Location)
            FileDelete($TC_Container_Location)
        Else
            SetError(96)
            Return 0
        endif
    EndIf
    
    $PID_TC_Format = Run('"C:\Program Files\TrueCrypt\TrueCrypt Format.exe"', @ScriptDir, @SW_HIDE)
    ;$PID_TC_Format = Run('"' & @ScriptDir & '\TrueCrypt\TrueCrypt Format.exe"', @ScriptDir, @SW_SHOW)

    ProcessWait($PID_TC_Format, 5)

    If $PID_TC_Format = 0 Then
        MsgBox(0, 'Error', '"TrueCrypt Format.exe" new PID could not be detected.')
        SetError(98)
        Return 0
    Else 
        If WinWait("[TITLE:TrueCrypt Volume Creation Wizard; CLASS:CustomDlg]", "", 10) = 0 Then
            MsgBox(0, 'Error', '"TrueCrypt Volume Creation Wizard" window not found...')
            SetError(97)
            Return 0
        Else

            $hWnds = WinList("[TITLE:TrueCrypt Volume Creation Wizard; CLASS:CustomDlg]", "")

            For $i = 0 To UBound($hWnds) - 1
                If WinGetProcess($hWnds[$i][1]) = $PID_TC_Format Then $hWnd_TC_Volume_Creation_Wizard = $hWnds[$i][1]
            Next

            If $hWnd_TC_Volume_Creation_Wizard <> 0 Then
                ConsoleWrite('Step 01: Found TrueCrypt Volume Creation Wizard hWnd: ' & $hWnd_TC_Volume_Creation_Wizard & @CRLF)
                $TC_Volume_Creation_Wizard_Error_Code = 1
            Else
                $b_TC_Volume_Creation_Wizard_failed = True
            EndIf

            If $b_TC_Volume_Creation_Wizard_failed = False Then
                $TC_Timer = TimerInit()
                While TimerDiff($TC_Timer) < 5000
                    If StringInStr(WinGetText($hWnd_TC_Volume_Creation_Wizard), "Encrypt the system partition or entire system drive") Then
                        ControlClick($hWnd_TC_Volume_Creation_Wizard, '', '[CLASS:Button; INSTANCE:3]')
                        ConsoleWrite('Step 02: Create File Container' & @CRLF)
                        $TC_Volume_Creation_Wizard_Error_Code = 2
                        ExitLoop
                    Else
                        $b_TC_Volume_Creation_Wizard_failed = True
                    EndIf
                WEnd
            EndIf

            If $b_TC_Volume_Creation_Wizard_failed = False Then
                $TC_Timer = TimerInit()
                While TimerDiff($TC_Timer) < 5000
                    If StringInStr(WinGetText($hWnd_TC_Volume_Creation_Wizard), "Volume Type") Then
                        ControlClick($hWnd_TC_Volume_Creation_Wizard, '', '[CLASS:Button; INSTANCE:3]')
                        ConsoleWrite('Step 03: Select Standard Type' & @CRLF)
                        $TC_Volume_Creation_Wizard_Error_Code = 3
                        ExitLoop
                    Else
                        $b_TC_Volume_Creation_Wizard_failed = True
                    EndIf
                WEnd
            EndIf

            If $b_TC_Volume_Creation_Wizard_failed = False Then
                $TC_Timer = TimerInit()
                While TimerDiff($TC_Timer) < 5000
                    If StringInStr(WinGetText($hWnd_TC_Volume_Creation_Wizard), "Volume Location") Then
                        ControlSetText($hWnd_TC_Volume_Creation_Wizard, '', '[CLASS:Edit; INSTANCE:1]', $TC_Container_Location, 1)
                        If ControlGetText($hWnd_TC_Volume_Creation_Wizard, '', '[CLASS:Edit; INSTANCE:1]') = $TC_Container_Location Then
                            ControlClick($hWnd_TC_Volume_Creation_Wizard, '', '[CLASS:Button; INSTANCE:3]')
                            ConsoleWrite('Step 04: Set Container location to ' & $TC_Container_Location & @CRLF)
                            $TC_Volume_Creation_Wizard_Error_Code = 4
                            ExitLoop
                        EndIf
                    Else
                        $b_TC_Volume_Creation_Wizard_failed = True
                    EndIf
                WEnd
            EndIf

            If $b_TC_Volume_Creation_Wizard_failed = False Then
                $TC_Timer = TimerInit()
                While TimerDiff($TC_Timer) < 5000
                    If StringInStr(WinGetText($hWnd_TC_Volume_Creation_Wizard), "Encryption Options") Then
                        ControlCommand($hWnd_TC_Volume_Creation_Wizard, "", "[CLASS:ComboBox; INSTANCE:1]", "SelectString", $TC_Container_Encryption)
                        If ControlCommand($hWnd_TC_Volume_Creation_Wizard, "", "[CLASS:ComboBox; INSTANCE:1]", "GetCurrentSelection", "") = $TC_Container_Encryption Then
                            ControlClick($hWnd_TC_Volume_Creation_Wizard, '', '[CLASS:Button; INSTANCE:3]')
                            ConsoleWrite('Step 05: Set Encryption Algorithm to ' & $TC_Container_Encryption & @CRLF)
                            $TC_Volume_Creation_Wizard_Error_Code = 5
                            ExitLoop
                        EndIf
                    Else
                        $b_TC_Volume_Creation_Wizard_failed = True
                    EndIf
                WEnd
            EndIf

            If $b_TC_Volume_Creation_Wizard_failed = False Then
                $TC_Timer = TimerInit()
                While TimerDiff($TC_Timer) < 5000
                    If StringInStr(WinGetText($hWnd_TC_Volume_Creation_Wizard), "Volume Size") Then
                        If _WinAPI_GetWindowLong(ControlGetHandle($hWnd_TC_Volume_Creation_Wizard, '', '[CLASS:Button; INSTANCE:6]'), $GWL_STYLE) <> 1342373897 Then
                            ControlClick($hWnd_TC_Volume_Creation_Wizard, "", ControlGetHandle($hWnd_TC_Volume_Creation_Wizard, '', '[CLASS:Button; INSTANCE:6]'))
                        ElseIf _WinAPI_GetWindowLong(ControlGetHandle($hWnd_TC_Volume_Creation_Wizard, '', '[CLASS:Button; INSTANCE:6]'), $GWL_STYLE) = 1342373897 Then
                            ConsoleWrite('Step 06: Select KB as Container Size' & @CRLF)
                            $TC_Volume_Creation_Wizard_Error_Code = 6
                            ExitLoop
                        EndIf
                    Else
                        $b_TC_Volume_Creation_Wizard_failed = True
                    EndIf
                WEnd
            EndIf

            If $b_TC_Volume_Creation_Wizard_failed = False Then
                $TC_Timer = TimerInit()
                While TimerDiff($TC_Timer) < 5000
                    If StringInStr(WinGetText($hWnd_TC_Volume_Creation_Wizard), "Volume Size") Then
                        ControlSetText($hWnd_TC_Volume_Creation_Wizard, '', '[CLASS:Edit; INSTANCE:1]', $TC_Container_Size_KB, 1)
                        If ControlGetText($hWnd_TC_Volume_Creation_Wizard, '', '[CLASS:Edit; INSTANCE:1]') = $TC_Container_Size_KB Then
                            ControlClick($hWnd_TC_Volume_Creation_Wizard, '', '[CLASS:Button; INSTANCE:3]')
                            ConsoleWrite('Step 07: Set Container Size to ' & $TC_Container_Size_KB & ' KB' & @CRLF)
                            $TC_Volume_Creation_Wizard_Error_Code = 7
                            ExitLoop
                        EndIf
                    Else
                        $b_TC_Volume_Creation_Wizard_failed = True
                    EndIf
                WEnd
            EndIf

            If $b_TC_Volume_Creation_Wizard_failed = False Then
                $TC_Timer = TimerInit()
                While TimerDiff($TC_Timer) < 5000
                    If StringInStr(WinGetText($hWnd_TC_Volume_Creation_Wizard), "Volume Password") Then
                        ControlClick($hWnd_TC_Volume_Creation_Wizard, '', '[CLASS:Button; INSTANCE:6]')
                        ControlSetText($hWnd_TC_Volume_Creation_Wizard, '', '[CLASS:Edit; INSTANCE:1]', $TC_Container_Password, 1)
                        If ControlGetText($hWnd_TC_Volume_Creation_Wizard, '', '[CLASS:Edit; INSTANCE:1]') = $TC_Container_Password Then
                            ControlSetText($hWnd_TC_Volume_Creation_Wizard, '', '[CLASS:Edit; INSTANCE:2]', $TC_Container_Password, 1)
                            If ControlGetText($hWnd_TC_Volume_Creation_Wizard, '', '[CLASS:Edit; INSTANCE:2]') = $TC_Container_Password Then
                                ControlClick($hWnd_TC_Volume_Creation_Wizard, '', '[CLASS:Button; INSTANCE:3]')
                                ConsoleWrite('Step 08: Set Container Password to "' & $TC_Container_Password & '"' & @CRLF)
                                $TC_Volume_Creation_Wizard_Error_Code = 8
                                ExitLoop
                            EndIf
                        EndIf
                    Else
                        $b_TC_Volume_Creation_Wizard_failed = True
                    EndIf
                WEnd
                ControlClick("[TITLE:TrueCrypt Volume Creation Wizard; CLASS:#32770]", '', '[CLASS:Button; INSTANCE:1]')
            EndIf

            If $b_TC_Volume_Creation_Wizard_failed = False Then
                $TC_Timer = TimerInit()
                While TimerDiff($TC_Timer) < 5000
                    If WinExists("[TITLE:TrueCrypt Volume Creation Wizard; CLASS:#32770]", "") = 1 Then ControlClick("[TITLE:TrueCrypt Volume Creation Wizard; CLASS:#32770]", '', '[CLASS:Button; INSTANCE:1]')
                    If StringInStr(WinGetText($hWnd_TC_Volume_Creation_Wizard), "Volume Format") Then
                        ControlCommand($hWnd_TC_Volume_Creation_Wizard, "", "[CLASS:ComboBox; INSTANCE:1]", "SelectString", $TC_Container_Filesystem)
                        If ControlCommand($hWnd_TC_Volume_Creation_Wizard, "", "[CLASS:ComboBox; INSTANCE:1]", "GetCurrentSelection", "") = $TC_Container_Filesystem Then
                            ConsoleWrite('Step 09: Set Container File Format to ' & $TC_Container_Filesystem & @CRLF)
                            $TC_Volume_Creation_Wizard_Error_Code = 9
                            ControlClick($hWnd_TC_Volume_Creation_Wizard, '', '[CLASS:Button; INSTANCE:3]')
                            ExitLoop
                        EndIf
                    Else
                        $b_TC_Volume_Creation_Wizard_failed = True
                    EndIf
                WEnd
            EndIf

            If $b_TC_Volume_Creation_Wizard_failed = False Then
                $TC_Container_Creation_Progress = ""
                $TC_Container_Creation_Progress_Save = ""
                $TC_Timer = TimerInit()
                While 1
                    $TC_Container_Creation_Progress = StringReplace(ControlGetText($hWnd_TC_Volume_Creation_Wizard, '', '[CLASS:Static; INSTANCE:12]'), "%", "")
                    If ($TC_Container_Creation_Progress <> $TC_Container_Creation_Progress_Save) AND $TC_Container_Creation_Progress <> 100 Then
                        $TC_Timer = TimerInit()
                        $TC_Container_Creation_Progress_Save = $TC_Container_Creation_Progress
                        ConsoleWrite("Step 10: Container creation progress: " & $TC_Container_Creation_Progress & "%" & @CRLF)
                    EndIf
                    If $TC_Container_Creation_Progress = 100.000 Then 
                        ConsoleWrite("Step 10: Container creation progress: " & $TC_Container_Creation_Progress & "%" & @CRLF)
                        $TC_Volume_Creation_Wizard_Error_Code = 10
                        ExitLoop
                    endif
                    If TimerDiff($TC_Timer) > 5000 Then
                        ConsoleWrite("Step 10: No progress in 5 seconds... failure?" & @CRLF)
                        $b_TC_Volume_Creation_Wizard_failed = True
                        ExitLoop
                    EndIf
                WEnd
            EndIf

            If $b_TC_Volume_Creation_Wizard_failed = False Then
                $TC_Timer = TimerInit()
                While 1
                    If WinExists("[TITLE:TrueCrypt Volume Creation Wizard; CLASS:#32770]", "The TrueCrypt volume has been successfully created.") = 1 Then
                        ControlClick("[TITLE:TrueCrypt Volume Creation Wizard; CLASS:#32770]", '', '[CLASS:Button; INSTANCE:1]')
                        ConsoleWrite("Step 11: Container creation finished successfully" & @CRLF)
                        $TC_Volume_Creation_Wizard_Error_Code = 11
                        ExitLoop
                    EndIf
                    If TimerDiff($TC_Timer) > 15000 Then
                        ConsoleWrite("Step 11: Progress at 100% but TC failed to notify about success for 15 seconds...failure?" & @CRLF)
                        $b_TC_Volume_Creation_Wizard_failed = True
                        ExitLoop
                    EndIf
                WEnd
            EndIf

        EndIf
    EndIf

    SetError($TC_Volume_Creation_Wizard_Error_Code)
    If $b_TC_Volume_Creation_Wizard_failed = true Then
        Return 0
    Else
        Return 1
    EndIf

EndFunc   ;==>_TC_Container_Create

Func OnAutoItExit()
    ProcessClose($PID_TC_Format)
EndFunc   ;==>OnAutoItExit
Link to comment
Share on other sites

Your ConsoleWrites at the start of the script are calling both functions. Try this as a start.

#include <winapi.au3>
#include <Constants.au3>

AutoItSetOption("WinDetectHiddenText", 1)
Opt("WinTitleMatchMode", 3)
Global $PID_TC_Format = 0
#cs
    These 2 lines are your problem
    ConsoleWrite("_FileGetProperty returned " & _FileGetProperty("") & @TAB & @error & @CRLF)
    ConsoleWrite("_TC_Container_Create("") returned " & _TC_Container_Create("") & @TAB & @error & @CRLF)
#ce

#include <File.au3> ; only used for the example script, not needed for the UDF
#include <Array.au3> ; only used for the example script, not needed for the UDF
$sFolder = FileSelectFolder("Select a folder to scan", "")
$sFolder &= ""
$aFiles = _FileListToArray($sFolder, "*", 1)
For $I = 1 To $aFiles[0]
    $aDetails = _FileGetProperty($sFolder & "\" & $aFiles[$I]) ; Returns an array with all properties of the file
;~  _ArrayDisplay($aDetails)
    ConsoleWrite("File size of " & $sFolder & "\" & $aFiles[$I] & " = " & _FileGetProperty($sFolder & "\" & $aFiles[$I], "size") & @CRLF) ; displays in the console the Size of the file
Next

Func _FileGetProperty($FGP_Path, Const $FGP_PROPERTY = "")
    $FGP_Path = StringRegExpReplace($FGP_Path, '"C:\Users\Cameron\volumes\readthis.txt', "") ; strip the quotes, if any from the incoming string
    If Not FileExists($FGP_Path) Then Return SetError(1, 0, "") ; path not found
    Local Const $objShell = ObjCreate("Shell.Application")
    If @error Then Return SetError(3, 0, "")
    Local $iPropertyCount = 300 ; arbitrary number used, Windows 7 only returns 288 properties, Windows XP only returns 38 (future proofing)
    Local Const $FGP_File = StringTrimLeft($FGP_Path, StringInStr($FGP_Path, "\", 0, -1))
    Local Const $FGP_Dir = StringTrimRight($FGP_Path, StringLen($FGP_File) + 1)
    Local Const $objFolder = $objShell.NameSpace($FGP_Dir)
    Local Const $objFolderItem = $objFolder.Parsename($FGP_File)
    Local $Return = "", $iError = 0
    If $FGP_PROPERTY Then
        For $I = 0 To $iPropertyCount
            If $objFolder.GetDetailsOf($objFolder.Items, $I) = $FGP_PROPERTY Then
                $Return = $objFolder.GetDetailsOf($objFolderItem, $I)
            EndIf
        Next
        If $Return = "" Then
            $iError = 2
        EndIf
    Else
        Local $av_ret[$iPropertyCount + 1][2] = [[0]]
        For $I = 1 To $iPropertyCount
            If $objFolder.GetDetailsOf($objFolder.Items, $I) Then
                $av_ret[$I][0] = $objFolder.GetDetailsOf($objFolder.Items, $I - 1)
                $av_ret[$I][1] = $objFolder.GetDetailsOf($objFolderItem, $I - 1)
                $av_ret[0][0] += 1
            EndIf
        Next
        ReDim $av_ret[$av_ret[0][0] + 1][2]
        If Not $av_ret[1][0] Then
            $iError = 2
            $av_ret = $Return
        Else
            $Return = $av_ret
        EndIf
    EndIf
    Return SetError($iError, 0, $Return)
EndFunc   ;==>_FileGetProperty

Func _TC_Container_Create($TC_Container_Location, $TC_Container_Encryption = "AES", $TC_Container_Hash = "RIPEMD-160", $TC_Container_Size_KB = 10000, $TC_Container_Password = "test", $TC_Container_Filesystem = "NTFS")

    Local $b_TC_Volume_Creation_Wizard_failed = False, $hWnd_TC_Volume_Creation_Wizard = 0, $TC_Volume_Creation_Wizard_Error_Code = 0

    ; NTFS min Size = 2829 KB
    ; FAT min Size = 275 KB
    ; ControlSetText() if it's just text you're sending. It's much faster.

    If Not $TC_Container_Location Then $TC_Container_Location = @ScriptDir & "\Test.tc"
    If $TC_Container_Size_KB < 275 Then $TC_Container_Size_KB = 275
    If $TC_Container_Size_KB < 2829 Then $TC_Container_Filesystem = "FAT"

    If FileExists($TC_Container_Location) Then
        If MsgBox(262420, "TCMyFiles", "The Target File" & @CRLF & @CRLF & $TC_Container_Location & @CRLF & @CRLF & "already exists. Do you want to overwrite the file?") <> 6 Then
            SetError(99)
            Return 0
        EndIf
        FileDelete($TC_Container_Location)
    Else
        $TC_Check_Location = FileOpen($TC_Container_Location, 10)
        If $TC_Check_Location <> -1 Then
            FileClose($TC_Check_Location)
            FileDelete($TC_Container_Location)
        Else
            SetError(96)
            Return 0
        EndIf
    EndIf

    $PID_TC_Format = Run('"C:\Program Files\TrueCrypt\TrueCrypt Format.exe"', @ScriptDir, @SW_HIDE)
    ;$PID_TC_Format = Run('"' & @ScriptDir & '\TrueCrypt\TrueCrypt Format.exe"', @ScriptDir, @SW_SHOW)

    ProcessWait($PID_TC_Format, 5)

    If $PID_TC_Format = 0 Then
        MsgBox(0, 'Error', '"TrueCrypt Format.exe" new PID could not be detected.')
        SetError(98)
        Return 0
    Else
        If WinWait("[TITLE:TrueCrypt Volume Creation Wizard; CLASS:CustomDlg]", "", 10) = 0 Then
            MsgBox(0, 'Error', '"TrueCrypt Volume Creation Wizard" window not found...')
            SetError(97)
            Return 0
        Else

            $hWnds = WinList("[TITLE:TrueCrypt Volume Creation Wizard; CLASS:CustomDlg]", "")

            For $I = 0 To UBound($hWnds) - 1
                If WinGetProcess($hWnds[$I][1]) = $PID_TC_Format Then $hWnd_TC_Volume_Creation_Wizard = $hWnds[$I][1]
            Next

            If $hWnd_TC_Volume_Creation_Wizard <> 0 Then
                ConsoleWrite('Step 01: Found TrueCrypt Volume Creation Wizard hWnd: ' & $hWnd_TC_Volume_Creation_Wizard & @CRLF)
                $TC_Volume_Creation_Wizard_Error_Code = 1
            Else
                $b_TC_Volume_Creation_Wizard_failed = True
            EndIf

            If $b_TC_Volume_Creation_Wizard_failed = False Then
                $TC_Timer = TimerInit()
                While TimerDiff($TC_Timer) < 5000
                    If StringInStr(WinGetText($hWnd_TC_Volume_Creation_Wizard), "Encrypt the system partition or entire system drive") Then
                        ControlClick($hWnd_TC_Volume_Creation_Wizard, '', '[CLASS:Button; INSTANCE:3]')
                        ConsoleWrite('Step 02: Create File Container' & @CRLF)
                        $TC_Volume_Creation_Wizard_Error_Code = 2
                        ExitLoop
                    Else
                        $b_TC_Volume_Creation_Wizard_failed = True
                    EndIf
                WEnd
            EndIf

            If $b_TC_Volume_Creation_Wizard_failed = False Then
                $TC_Timer = TimerInit()
                While TimerDiff($TC_Timer) < 5000
                    If StringInStr(WinGetText($hWnd_TC_Volume_Creation_Wizard), "Volume Type") Then
                        ControlClick($hWnd_TC_Volume_Creation_Wizard, '', '[CLASS:Button; INSTANCE:3]')
                        ConsoleWrite('Step 03: Select Standard Type' & @CRLF)
                        $TC_Volume_Creation_Wizard_Error_Code = 3
                        ExitLoop
                    Else
                        $b_TC_Volume_Creation_Wizard_failed = True
                    EndIf
                WEnd
            EndIf

            If $b_TC_Volume_Creation_Wizard_failed = False Then
                $TC_Timer = TimerInit()
                While TimerDiff($TC_Timer) < 5000
                    If StringInStr(WinGetText($hWnd_TC_Volume_Creation_Wizard), "Volume Location") Then
                        ControlSetText($hWnd_TC_Volume_Creation_Wizard, '', '[CLASS:Edit; INSTANCE:1]', $TC_Container_Location, 1)
                        If ControlGetText($hWnd_TC_Volume_Creation_Wizard, '', '[CLASS:Edit; INSTANCE:1]') = $TC_Container_Location Then
                            ControlClick($hWnd_TC_Volume_Creation_Wizard, '', '[CLASS:Button; INSTANCE:3]')
                            ConsoleWrite('Step 04: Set Container location to ' & $TC_Container_Location & @CRLF)
                            $TC_Volume_Creation_Wizard_Error_Code = 4
                            ExitLoop
                        EndIf
                    Else
                        $b_TC_Volume_Creation_Wizard_failed = True
                    EndIf
                WEnd
            EndIf

            If $b_TC_Volume_Creation_Wizard_failed = False Then
                $TC_Timer = TimerInit()
                While TimerDiff($TC_Timer) < 5000
                    If StringInStr(WinGetText($hWnd_TC_Volume_Creation_Wizard), "Encryption Options") Then
                        ControlCommand($hWnd_TC_Volume_Creation_Wizard, "", "[CLASS:ComboBox; INSTANCE:1]", "SelectString", $TC_Container_Encryption)
                        If ControlCommand($hWnd_TC_Volume_Creation_Wizard, "", "[CLASS:ComboBox; INSTANCE:1]", "GetCurrentSelection", "") = $TC_Container_Encryption Then
                            ControlClick($hWnd_TC_Volume_Creation_Wizard, '', '[CLASS:Button; INSTANCE:3]')
                            ConsoleWrite('Step 05: Set Encryption Algorithm to ' & $TC_Container_Encryption & @CRLF)
                            $TC_Volume_Creation_Wizard_Error_Code = 5
                            ExitLoop
                        EndIf
                    Else
                        $b_TC_Volume_Creation_Wizard_failed = True
                    EndIf
                WEnd
            EndIf

            If $b_TC_Volume_Creation_Wizard_failed = False Then
                $TC_Timer = TimerInit()
                While TimerDiff($TC_Timer) < 5000
                    If StringInStr(WinGetText($hWnd_TC_Volume_Creation_Wizard), "Volume Size") Then
                        If _WinAPI_GetWindowLong(ControlGetHandle($hWnd_TC_Volume_Creation_Wizard, '', '[CLASS:Button; INSTANCE:6]'), $GWL_STYLE) <> 1342373897 Then
                            ControlClick($hWnd_TC_Volume_Creation_Wizard, "", ControlGetHandle($hWnd_TC_Volume_Creation_Wizard, '', '[CLASS:Button; INSTANCE:6]'))
                        ElseIf _WinAPI_GetWindowLong(ControlGetHandle($hWnd_TC_Volume_Creation_Wizard, '', '[CLASS:Button; INSTANCE:6]'), $GWL_STYLE) = 1342373897 Then
                            ConsoleWrite('Step 06: Select KB as Container Size' & @CRLF)
                            $TC_Volume_Creation_Wizard_Error_Code = 6
                            ExitLoop
                        EndIf
                    Else
                        $b_TC_Volume_Creation_Wizard_failed = True
                    EndIf
                WEnd
            EndIf

            If $b_TC_Volume_Creation_Wizard_failed = False Then
                $TC_Timer = TimerInit()
                While TimerDiff($TC_Timer) < 5000
                    If StringInStr(WinGetText($hWnd_TC_Volume_Creation_Wizard), "Volume Size") Then
                        ControlSetText($hWnd_TC_Volume_Creation_Wizard, '', '[CLASS:Edit; INSTANCE:1]', $TC_Container_Size_KB, 1)
                        If ControlGetText($hWnd_TC_Volume_Creation_Wizard, '', '[CLASS:Edit; INSTANCE:1]') = $TC_Container_Size_KB Then
                            ControlClick($hWnd_TC_Volume_Creation_Wizard, '', '[CLASS:Button; INSTANCE:3]')
                            ConsoleWrite('Step 07: Set Container Size to ' & $TC_Container_Size_KB & ' KB' & @CRLF)
                            $TC_Volume_Creation_Wizard_Error_Code = 7
                            ExitLoop
                        EndIf
                    Else
                        $b_TC_Volume_Creation_Wizard_failed = True
                    EndIf
                WEnd
            EndIf

            If $b_TC_Volume_Creation_Wizard_failed = False Then
                $TC_Timer = TimerInit()
                While TimerDiff($TC_Timer) < 5000
                    If StringInStr(WinGetText($hWnd_TC_Volume_Creation_Wizard), "Volume Password") Then
                        ControlClick($hWnd_TC_Volume_Creation_Wizard, '', '[CLASS:Button; INSTANCE:6]')
                        ControlSetText($hWnd_TC_Volume_Creation_Wizard, '', '[CLASS:Edit; INSTANCE:1]', $TC_Container_Password, 1)
                        If ControlGetText($hWnd_TC_Volume_Creation_Wizard, '', '[CLASS:Edit; INSTANCE:1]') = $TC_Container_Password Then
                            ControlSetText($hWnd_TC_Volume_Creation_Wizard, '', '[CLASS:Edit; INSTANCE:2]', $TC_Container_Password, 1)
                            If ControlGetText($hWnd_TC_Volume_Creation_Wizard, '', '[CLASS:Edit; INSTANCE:2]') = $TC_Container_Password Then
                                ControlClick($hWnd_TC_Volume_Creation_Wizard, '', '[CLASS:Button; INSTANCE:3]')
                                ConsoleWrite('Step 08: Set Container Password to "' & $TC_Container_Password & '"' & @CRLF)
                                $TC_Volume_Creation_Wizard_Error_Code = 8
                                ExitLoop
                            EndIf
                        EndIf
                    Else
                        $b_TC_Volume_Creation_Wizard_failed = True
                    EndIf
                WEnd
                ControlClick("[TITLE:TrueCrypt Volume Creation Wizard; CLASS:#32770]", '', '[CLASS:Button; INSTANCE:1]')
            EndIf

            If $b_TC_Volume_Creation_Wizard_failed = False Then
                $TC_Timer = TimerInit()
                While TimerDiff($TC_Timer) < 5000
                    If WinExists("[TITLE:TrueCrypt Volume Creation Wizard; CLASS:#32770]", "") = 1 Then ControlClick("[TITLE:TrueCrypt Volume Creation Wizard; CLASS:#32770]", '', '[CLASS:Button; INSTANCE:1]')
                    If StringInStr(WinGetText($hWnd_TC_Volume_Creation_Wizard), "Volume Format") Then
                        ControlCommand($hWnd_TC_Volume_Creation_Wizard, "", "[CLASS:ComboBox; INSTANCE:1]", "SelectString", $TC_Container_Filesystem)
                        If ControlCommand($hWnd_TC_Volume_Creation_Wizard, "", "[CLASS:ComboBox; INSTANCE:1]", "GetCurrentSelection", "") = $TC_Container_Filesystem Then
                            ConsoleWrite('Step 09: Set Container File Format to ' & $TC_Container_Filesystem & @CRLF)
                            $TC_Volume_Creation_Wizard_Error_Code = 9
                            ControlClick($hWnd_TC_Volume_Creation_Wizard, '', '[CLASS:Button; INSTANCE:3]')
                            ExitLoop
                        EndIf
                    Else
                        $b_TC_Volume_Creation_Wizard_failed = True
                    EndIf
                WEnd
            EndIf

            If $b_TC_Volume_Creation_Wizard_failed = False Then
                $TC_Container_Creation_Progress = ""
                $TC_Container_Creation_Progress_Save = ""
                $TC_Timer = TimerInit()
                While 1
                    $TC_Container_Creation_Progress = StringReplace(ControlGetText($hWnd_TC_Volume_Creation_Wizard, '', '[CLASS:Static; INSTANCE:12]'), "%", "")
                    If ($TC_Container_Creation_Progress <> $TC_Container_Creation_Progress_Save) And $TC_Container_Creation_Progress <> 100 Then
                        $TC_Timer = TimerInit()
                        $TC_Container_Creation_Progress_Save = $TC_Container_Creation_Progress
                        ConsoleWrite("Step 10: Container creation progress: " & $TC_Container_Creation_Progress & "%" & @CRLF)
                    EndIf
                    If $TC_Container_Creation_Progress = 100.000 Then
                        ConsoleWrite("Step 10: Container creation progress: " & $TC_Container_Creation_Progress & "%" & @CRLF)
                        $TC_Volume_Creation_Wizard_Error_Code = 10
                        ExitLoop
                    EndIf
                    If TimerDiff($TC_Timer) > 5000 Then
                        ConsoleWrite("Step 10: No progress in 5 seconds... failure?" & @CRLF)
                        $b_TC_Volume_Creation_Wizard_failed = True
                        ExitLoop
                    EndIf
                WEnd
            EndIf

            If $b_TC_Volume_Creation_Wizard_failed = False Then
                $TC_Timer = TimerInit()
                While 1
                    If WinExists("[TITLE:TrueCrypt Volume Creation Wizard; CLASS:#32770]", "The TrueCrypt volume has been successfully created.") = 1 Then
                        ControlClick("[TITLE:TrueCrypt Volume Creation Wizard; CLASS:#32770]", '', '[CLASS:Button; INSTANCE:1]')
                        ConsoleWrite("Step 11: Container creation finished successfully" & @CRLF)
                        $TC_Volume_Creation_Wizard_Error_Code = 11
                        ExitLoop
                    EndIf
                    If TimerDiff($TC_Timer) > 15000 Then
                        ConsoleWrite("Step 11: Progress at 100% but TC failed to notify about success for 15 seconds...failure?" & @CRLF)
                        $b_TC_Volume_Creation_Wizard_failed = True
                        ExitLoop
                    EndIf
                WEnd
            EndIf

        EndIf
    EndIf

    SetError($TC_Volume_Creation_Wizard_Error_Code)
    If $b_TC_Volume_Creation_Wizard_failed = True Then
        Return 0
    Else
        Return 1
    EndIf

EndFunc   ;==>_TC_Container_Create

Func OnAutoItExit()
    ProcessClose($PID_TC_Format)
EndFunc   ;==>OnAutoItExit
BTW, you had several other errors in there that would have prevented this from giving you the results you wanted, they have been fixed.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

Thank you very much BrewManNH! I have a few questions I'd like to throw out as well, considering I am not quite familiar with AutoIt or scripting and I just need to throw something together quickly.

Will getFileProperty() scan a folder for my properties txt file, in my case, readthis.txt, and pull from there?

Is it possible to set a container location instead of it defaulting to the folder that holds the script file?

Just a bit confused here, any advice regarding what I'm trying to accomplish would be great.

Thanks all.

Link to comment
Share on other sites

 

Thank you very much BrewManNH! I have a few questions I'd like to throw out as well, considering I am not quite familiar with AutoIt or scripting and I just need to throw something together quickly.

 

Will getFileProperty() scan a folder for my properties txt file, in my case, readthis.txt, and pull from there?

If you're asking whether it will read the file and do something with the contents of the text file, then no it won't. You'll have to read it in and parse the file for what you want.

 

 

Is it possible to set a container location instead of it defaulting to the folder that holds the script file?

I'm not sure what it is you're asking here, can you clarify that?  Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

This is what I'd like to accomplish:

Have a preconfigured text file of properties such as volumeproperties.txt -> read these values in to be used in Func _TC_Container_Create($TC_Container_Location, $TC_Container_Encryption = "AES", ... etc)

then of course execute _TC_Container_Create func and create the Container with the values that were specified in volumeproperties.txt

^This is all that I need to accomplish here^

Secondly, regarding the confusion, in my function declaration $TC_Container_Location is not given some = "*abirtrary something*" like the other variables. Is there a clear reason for this, or am I able to implement a variable (in this case, the path where I'd like the volume to be created)

Link to comment
Share on other sites

From looking at the _TC_Container_Create function, you can set the location for the container by passing the path and file name to the function as its first parameter, if you send it a blank string it will set it to the script dir and give it the name Test.tc.

I'd need to know what you have in the file "volumeproperties.txt" to be able to tell you what to do with it. If it's just a list of file names you could load it into an array with _FileReadToArray and loop through the array. But, like I said, it's hard to tell you exactly without knowing what is in it.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

From looking at the _TC_Container_Create function, you can set the location for the container by passing the path and file name to the function as its first parameter, if you send it a blank string it will set it to the script dir and give it the name Test.tc.

That's KaFu's function just for the record.

UDF List:

 
_AdapterConnections()_AlwaysRun()_AppMon()_AppMonEx()_ArrayFilter/_ArrayReduce_BinaryBin()_CheckMsgBox()_CmdLineRaw()_ContextMenu()_ConvertLHWebColor()/_ConvertSHWebColor()_DesktopDimensions()_DisplayPassword()_DotNet_Load()/_DotNet_Unload()_Fibonacci()_FileCompare()_FileCompareContents()_FileNameByHandle()_FilePrefix/SRE()_FindInFile()_GetBackgroundColor()/_SetBackgroundColor()_GetConrolID()_GetCtrlClass()_GetDirectoryFormat()_GetDriveMediaType()_GetFilename()/_GetFilenameExt()_GetHardwareID()_GetIP()_GetIP_Country()_GetOSLanguage()_GetSavedSource()_GetStringSize()_GetSystemPaths()_GetURLImage()_GIFImage()_GoogleWeather()_GUICtrlCreateGroup()_GUICtrlListBox_CreateArray()_GUICtrlListView_CreateArray()_GUICtrlListView_SaveCSV()_GUICtrlListView_SaveHTML()_GUICtrlListView_SaveTxt()_GUICtrlListView_SaveXML()_GUICtrlMenu_Recent()_GUICtrlMenu_SetItemImage()_GUICtrlTreeView_CreateArray()_GUIDisable()_GUIImageList_SetIconFromHandle()_GUIRegisterMsg()_GUISetIcon()_Icon_Clear()/_Icon_Set()_IdleTime()_InetGet()_InetGetGUI()_InetGetProgress()_IPDetails()_IsFileOlder()_IsGUID()_IsHex()_IsPalindrome()_IsRegKey()_IsStringRegExp()_IsSystemDrive()_IsUPX()_IsValidType()_IsWebColor()_Language()_Log()_MicrosoftInternetConnectivity()_MSDNDataType()_PathFull/GetRelative/Split()_PathSplitEx()_PrintFromArray()_ProgressSetMarquee()_ReDim()_RockPaperScissors()/_RockPaperScissorsLizardSpock()_ScrollingCredits_SelfDelete()_SelfRename()_SelfUpdate()_SendTo()_ShellAll()_ShellFile()_ShellFolder()_SingletonHWID()_SingletonPID()_Startup()_StringCompact()_StringIsValid()_StringRegExpMetaCharacters()_StringReplaceWholeWord()_StringStripChars()_Temperature()_TrialPeriod()_UKToUSDate()/_USToUKDate()_WinAPI_Create_CTL_CODE()_WinAPI_CreateGUID()_WMIDateStringToDate()/_DateToWMIDateString()Au3 script parsingAutoIt SearchAutoIt3 PortableAutoIt3WrapperToPragmaAutoItWinGetTitle()/AutoItWinSetTitle()CodingDirToHTML5FileInstallrFileReadLastChars()GeoIP databaseGUI - Only Close ButtonGUI ExamplesGUICtrlDeleteImage()GUICtrlGetBkColor()GUICtrlGetStyle()GUIEventsGUIGetBkColor()Int_Parse() & Int_TryParse()IsISBN()LockFile()Mapping CtrlIDsOOP in AutoItParseHeadersToSciTE()PasswordValidPasteBinPosts Per DayPreExpandProtect GlobalsQueue()Resource UpdateResourcesExSciTE JumpSettings INISHELLHOOKShunting-YardSignature CreatorStack()Stopwatch()StringAddLF()/StringStripLF()StringEOLToCRLF()VSCROLLWM_COPYDATAMore Examples...

Updated: 22/04/2018

Link to comment
Share on other sites

You could make this much easier if you used an INI file for the information, and use the Ini* functions to read it.

Then you could set it up like this.

[settings]
ContainerLocation=C:\SomePathHere
FileName=SomeFileName

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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