Mit AUtoIt automatischen TrueCryptContainer erstellen

  • Hallo Leute,

    bin ganz neu hier und habe heute das erste mal von Auto IT gehört xD

    Ich würde gerne damit einen TrueCryptContainer automatisch erstellen lassen. Ich habe dazu ein Skript im Internet gefunden. Leider funktioniert es nicht ganz so wie ich es brauche, da ich gerne DYNAMISCHE container hätte. Dazu muss eine Checkbox betätigt werden und die Abfrage mit "Ja" beantwortet werden. Ich habe aber keine Ahnung wie man das macht.
    Hier ist der Quellcode der genau diesen Schritt behandelt Ich Danke im voraus und hoffe jemand kann mir einen TIpp geben


    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

    Einmal editiert, zuletzt von Mito (5. Juli 2013 um 16:33)

  • Hallo und Willkommen im Forum!

    Viele lesen sich ein Thema lieber durch bzw. Antworten / Helfen dann wenn das Script was gepostet wird
    sich in "Autoit-Quellcode" gepostet wurde.
    Das heißt am anfang des Scriptes kommt ein:

    PHP
    [autoit]


    und am ende ein:

    PHP
    [/autoit]

    Beispiel:

    PHP
    [autoit]Msgbox(0,"Test Titel","Test Text")[/autoit]


    Sieht folgend aus wenn man den Post abschickt:

    [autoit]

    Msgbox(0,"Test Titel","Test Text")

    [/autoit]

    Bei sehr langen Scripten immer bitte das gleiche mit Spoiler machen ;)

    PHP
    [spoiler][autoit]Msgbox(0,"Test Titel","Test Text")[/autoit][/spoiler]
    Spoiler anzeigen
    [autoit]

    Msgbox(0,"Test Titel","Test Text")

    [/autoit]

    Zum Thema:

    Da Ich mit Automatisierung von Programmen nicht so gut auskenne und nichts falsches schreiben will.


    Ps. Autoit ist ein guter Einstieg in dem Programmieren und kann ich dir nur empfehlen sich etwas mehr damit zu befassen.
    Bei Fragen einfach fragen unser Forum beißt dich nicht, aber besser voher die Forum Suche benutzen und von ,,Bots" wegbleiben!
    Auch wenn dein Script ein wenig drann kommt denk ich mal das es noch in der Sicheren-Grenze ist.
    (Bot´s = Robots, Programme zum Automartisieren von Anwendungen und Spielen)

    Sind TV-Quizfragen zu einfach? A) Ja B) Harry Potter

    Spoiler anzeigen

    Ich gebe zu dieser Post hat wahrscheinlich nicht viel geholfen,
    aber ich versuche wenigstens zu helfen :rolleyes:

  • Da ich mal vermute, dass du diese Funktion aus dem englischen Forum verwendest (poste das nächstemal bitte den kompletten code und einen Link zu deiner Quelle) habe ich mir das mal angeschaut und die Funktion ein wenig verändert. Es gibt nun zwei neue Parameter, einmal um die dynamische Größe zu aktivieren und einmal um die Sichtbarkeit des Fensters zu aktivieren. Außerdem wurde das Zeitlimit nach Fertigstellung von 15 auf 60 Sekunden angehoben, da es bei meinem 1GB Container grundsätzlich länger gedauert hatte bis das betreffende Fenster erschien. Das Problem tritt aber ohnehin nur bei einem "nicht dynamischen" container auf. Allerdings kam es bei meinen Tests gelegentlich vor, dass der frisch erstellte container nicht dismounted werden konnte, weil er angeblich noch vom System verwendet wurde. Hier sollte man ggf. noch eine zusätzliche Abfrage in die Funktion einbauen um in solch einem Fall die Meldung mit "Force dismount" zu bestätigen. Das ist hier aber sehr selten vorgekommen und ich konnte die Meldung daher nicht analysieren und entsprechend in die Funktion einbauen.

    Das ganze wurde mit einer portable Intallation von TC 7.1a getestet. Da sich jederzeit etwas an den Dialogen ändern könnte ist nicht gewährleistet, dass es auch mit zukünftigen Versionen reibungslos funktioniert. Schöner wäre es wenn die Entwickler einen cmdline Modus für die Container Erstellung einbauen würden, wie es in der Linux und Mac Version der Fall ist.

    Spoiler anzeigen
    [autoit]


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

    [/autoit] [autoit][/autoit] [autoit]

    AutoItSetOption("WinDetectHiddenText", 1)
    Opt("WinTitleMatchMode", 3)

    [/autoit] [autoit][/autoit] [autoit]

    Global $PID_TC_Format = 0

    [/autoit] [autoit][/autoit] [autoit]

    OnAutoItExitRegister("OnAutoItExit")

    [/autoit] [autoit][/autoit] [autoit]

    ConsoleWrite("_TC_Container_Create("") returned " & _TC_Container_Create(@ScriptDir & "\testcontainer.tc","AES","RIPEMD-160",1024000,"1234","NTFS",True,True) & @TAB & @error & @crlf)

    [/autoit] [autoit][/autoit] [autoit]

    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",$TC_Container_Dynamic=False,$showIt=False)

    [/autoit] [autoit][/autoit] [autoit]

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

    [/autoit] [autoit][/autoit] [autoit]

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

    [/autoit] [autoit][/autoit] [autoit]

    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"

    [/autoit] [autoit][/autoit] [autoit]

    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

    [/autoit] [autoit][/autoit] [autoit]

    If $showIt = True Then
    $PID_TC_Format = Run('"' & @ScriptDir & '\TrueCrypt\TrueCrypt Format.exe"', @ScriptDir, @SW_SHOW)
    Else
    $PID_TC_Format = Run('"' & @ScriptDir & '\TrueCrypt\TrueCrypt Format.exe"', @ScriptDir, @SW_HIDE)
    EndIf

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    ProcessWait($PID_TC_Format, 5)

    [/autoit] [autoit][/autoit] [autoit]

    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

    [/autoit] [autoit][/autoit] [autoit]

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

    [/autoit] [autoit][/autoit] [autoit]

    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

    [/autoit] [autoit][/autoit] [autoit]

    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

    [/autoit] [autoit][/autoit] [autoit]

    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

    [/autoit] [autoit][/autoit] [autoit]

    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

    [/autoit] [autoit][/autoit] [autoit]

    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

    [/autoit] [autoit][/autoit] [autoit]

    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

    [/autoit] [autoit][/autoit] [autoit]

    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

    [/autoit] [autoit][/autoit] [autoit]

    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

    [/autoit] [autoit][/autoit] [autoit]

    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

    [/autoit] [autoit][/autoit] [autoit]

    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
    If $TC_Container_Dynamic = True Then
    ConsoleWrite('Step 09a: Set Container File Format to Dynamic ' & $TC_Container_Dynamic & @CRLF)
    If ControlCommand($hWnd_TC_Volume_Creation_Wizard,"","[CLASS:Button; TEXT:Dynamic]","IsChecked","") = 0 Then
    ControlCommand($hWnd_TC_Volume_Creation_Wizard,"","[CLASS:Button; TEXT:Dynamic]","Check","")
    WinWait("TrueCrypt Volume Creation Wizard","Dynamic container is a pre-allocated NTFS sparse file",5)
    ControlClick("TrueCrypt Volume Creation Wizard","Dynamic container is a pre-allocated NTFS sparse file",'[CLASS:Button; INSTANCE:1]')
    EndIf
    EndIf
    ControlClick($hWnd_TC_Volume_Creation_Wizard, '', '[CLASS:Button; INSTANCE:3]')
    ExitLoop
    EndIf
    Else
    $b_TC_Volume_Creation_Wizard_failed = True
    EndIf
    WEnd
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    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

    [/autoit] [autoit][/autoit] [autoit]

    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) > 60000 Then
    ConsoleWrite("Step 11: Progress at 100% but TC failed to notify about success for 60 seconds...failure?" & @CRLF)
    $b_TC_Volume_Creation_Wizard_failed = True
    ExitLoop
    EndIf
    WEnd
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

    If $b_TC_Volume_Creation_Wizard_failed = False And $TC_Container_Dynamic = True Then
    $TC_Timer = TimerInit()
    While 1
    If WinExists("[TITLE:TrueCrypt Volume Creation Wizard; CLASS:#32770]", "Note that the size of the dynamic container reported by Windows") = 1 Then
    ControlClick("[TITLE:TrueCrypt Volume Creation Wizard; CLASS:#32770]", "Note that the size of the dynamic container reported by Windows", '[CLASS:Button; INSTANCE:1]')
    ConsoleWrite("Step 12: Warn dialog about dynamic volume size closed successfully" & @CRLF)
    $TC_Volume_Creation_Wizard_Error_Code = 12
    ExitLoop
    EndIf
    If TimerDiff($TC_Timer) > 15000 Then
    ConsoleWrite("Step 12: Warn dialog about dynamic volume size was not found!" & @CRLF)
    $b_TC_Volume_Creation_Wizard_failed = True
    ExitLoop
    EndIf
    WEnd
    EndIf
    EndIf
    EndIf

    [/autoit] [autoit][/autoit] [autoit]

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

    [/autoit] [autoit][/autoit] [autoit]

    EndFunc ;==>_TC_Container_Create

    [/autoit] [autoit][/autoit] [autoit]

    Func OnAutoItExit()
    $debug = ProcessClose($PID_TC_Format)
    ConsoleWrite("Exiting TC debug: Return code(" & $debug & ") Error code(" & @error & ")" & @CRLF)
    EndFunc ;==>OnAutoItExit

    [/autoit]
  • COOOL Danke !

    Ja das mit dem Code hatte nicht so recht funktioniert weil die Formatierung falsch war, ich werde es mir aber merken !

    Der Code funktioniert soweit richtig gut ! Habe mir auch noch eingebaut das ich paar Paramter per Comandozeile übergeben kann.

    Danke nochmals

    Einmal editiert, zuletzt von Mito (8. Juli 2013 um 15:30)