Vergleichen der Benutzerdefinierten [Sektion]

  • Hallo Zusammen

    Habe in der Zwischenzeit einiges im AutoIT dazu gelernt. Wie Z.b. auch ein Array in der
    benutzerdefinierten [Sektion] ich auslesen kann, dennoch besteht der Fehler im Code das die
    „MAC Adresse“ der gewählten [Sektion] nicht vergleicht und nicht gefunden wird.

    Dass Ziel währe:
    - Benutzer wählt sein Laptop Modell Z.b.“Z60M„, OK
    - Dies wird überprüft mit der dazugehörenden MAC Adresse in der Sektion [Z60M], TEILS
    - Der Code fährt dann weiter wenn Sektion [Z60M] eine Übereinstimmung gefunden wurde., STOP
    - Wenn dies nicht der fall ist bricht Programm ab und beendet sich. OK

    Was momentan nicht korrekt abläuft ist die Überprüfung der MAC Adresse in der [Sektion]
    dennoch sehe ich das meine abfrage der Sektion sich in der korrekten spalte bewegt.

    Denn vergleich ist mir aber noch nicht ganz klar und währe deshalb um Rat und Hilfe
    wirklich sehr dankbar und angewiesen.

    Bin überzogen das sich mein Fehler in der Region [66-107] befindet.
    Danke für eure Hilfe
    MC


    CODE:

    Spoiler anzeigen
    [autoit]

    #Include <array.au3>
    #include <file.au3>
    #include <GUIConstantsEx.au3>

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

    Opt('MustDeclareVars', 1)
    Example()
    Func Example()

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

    Local $aboutitem, $helpmenu, $n1, $n2, $msg, $font, $var, $cfgfile, $ip, $s
    Local $file, $cfgfile, $filelist, $exititem, $section, $msgbox, $restore
    ;/ MAC TEIL
    Local $filename, $source_filename, $found, $array, $text, $macs, $filearray, $y, $j, $section1

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

    GUICreate("Info Fenster - Restore now", 300, 300) ; Fenster Balken

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

    $filelist = GUICtrlCreateMenu("&File")
    $exititem = GUICtrlCreateMenuItem("Exit", $filelist)
    $helpmenu = GUICtrlCreateMenu("&?")
    $aboutitem = GUICtrlCreateMenuItem("&About", $helpmenu)

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

    $font = "Arial"
    GUISetFont(11, 400, 3, $font) ; Font
    GUICtrlCreateLabel("Wählen Sie das passende Image", 11, 30)

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

    $n1=GUICtrlCreateCombo("", 10, 50)

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

    $section=IniReadSection("laptop.ini", "section")
    For $i=1 To UBound($section)-1

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

    GuiCtrlSetData($n1, IniRead("laptop.ini", "section", $i, ""))
    Next

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

    $n2 = GUICtrlCreateButton("Wiederherstellen", 10, 110, 120)

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

    DriveMapAdd("r:", "\\xyz\e$\xyz\Data\images\PC_laptops\laptop vat", 0, "login", "")

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

    GUICtrlSetState(-1, $GUI_FOCUS) ; the focus is on this button
    GUISetState()

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

    Do
    $msg = GUIGetMsg()
    Switch $msg
    ;Case $exititem
    Case $aboutitem
    GUISetFont(14, 400, 1, $font)
    GUICtrlCreateLabel(""&Chr(10)&Chr(10)&""&Chr(10)&"Version 0.5", 10, 180, 320)
    Case $exititem
    ;Case $exititem, $GUI_EVENT_CLOSE
    Exit

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

    EndSwitch
    ;ExitLoop

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

    $ip=StringInStr(@IPAddress1,"192.168")
    $msg = GUIGetMsg()
    If $msg = $n2 Then
    $msgbox=MsgBox(1, "Achtung !","Das Laptop model lautet: "&GuiCtrlRead($n1)&Chr(10)&"Die zugewiesene IP-Adresse lautet: "&@IPAddress1&Chr(10)&Chr(10)&"Klicken Sie < OK > zum Starten der Wiederherstellung "&Chr(10)&"Klicken Sie < Abbrechen > zum Abbrechen der Auswahl") ; anzeige gewähltes Image

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

    ; START MAC
    $filename = "ipconfig.txt"

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

    ; mit ipconfig Mac auslesen

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

    RunWait(@ComSpec & " /c ipconfig /all > " & $filename, "", @SW_HIDE)
    Dim $array
    _FileReadToArray($filename, $array)
    $text = _ArrayToString($array, ";")

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

    msgbox(1, "", GuiCtrlRead($n1)) ; uberprüfung des gewählten laptop

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

    $section1 = IniReadSection("laptop.ini", ""&GuiCtrlRead($n1)&"" )
    For $z=1 To UBound($section1)-1
    msgbox(1, "", $z) ; Only for TEST
    Next

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

    $macs = StringRegExp($text, "(..-..-..-..-..-..)", 3)
    msgbox(1, "", $text)

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

    Dim $filearray

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

    For $y=0 To UBound($filearray)-1
    For $j=0 to ubound($macs)-1

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

    if stringinstr($filearray[$y],$macs[$j]) Then
    $found = $macs[$j]
    ExitLoop
    EndIf
    Next
    Next

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

    ; Ausgabe
    If $found <> "" Then
    MsgBox(0, "MAC-Adresse gefunden", "Ihre MAC-Adresse wurde gefunden ("&$found&")")
    Else
    MsgBox(0, "MAC-Adresse nicht gefunden", "Ihre MAC-Adresse wurde nicht gefunden.")
    FileDelete($filename)
    Exit
    EndIf

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

    ; temporäre Datei löschen
    FileDelete($filename)
    ; STOP MAC

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

    if $msgbox = 2 Then Exit

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

    DriveMapAdd("r:", "\\xyz\e$\xyz\Data\images\PC_laptops\laptop vat", 0, "login", "")
    Sleep(Random(1000, 3000))

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

    $cfgfile = FileOpen("b:\"&GUICtrlRead($n1)&".cfg", 1)
    FileWriteLine($cfgfile,"; * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *")
    FileWriteLine($cfgfile,"; * -- Restore Script for Laptop.ini | Time "&@HOUR&":"&@MIN&":"&@SEC&" ---> Datum "&@MDAY&"."&@MON&"."&@YEAR&" -- *")
    FileWriteLine($cfgfile,"; * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *")
    FileWriteLine($cfgfile, "mouse=no")
    FileWriteLine($cfgfile, "filesystem=ntfs")
    FileWriteLine($cfgfile, "disk=0")
    FileWriteLine($cfgfile, "main_part=1")
    FileWriteLine($cfgfile, "def_level=6")
    FileWriteLine($cfgfile, "quit=nobadsector")
    FileWriteLine($cfgfile, "automatic_naming=yes")
    FileWriteLine($cfgfile, "file=r:\"&GUICtrlRead($n1))
    FileClose($cfgfile)
    Sleep(Random(1000, 2000))

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

    $file = FileOpen("b:\Restoremenow.cmd", 1)
    FileWriteLine($file, "REM * * * * * * * * * * * * * * * * * * * * * * *")
    FileWriteLine($file, "REM * --- Zeit " & @HOUR & ":" &@MIN & ":" &@SEC &" -> Datum "& @MDAY & "." & @MON & "." & @YEAR & " --- *")
    FileWriteLine($file, "REM * * * * * * * * * * * * * * * * * * * * * * *")
    FileWriteLine($file, "x:\programs\imager\spartwin.ex_e -r -f b:\"& GUICtrlRead($n1) &".cfg")

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

    FileClose($file)

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

    Sleep(Random(1000, 2000))

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

    RunWait("b:\Restoremenow.cmd", "", @SW_MAXIMIZE)

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

    ;Run("b:\Restoremenow.cmd", "", @SW_MAXIMIZE)
    FileMove("b:\"&GUICtrlRead($n1)&".cfg", "b:\"&GUICtrlRead($n1)&".txt")
    FileMove("b:\Restoremenow.cmd", "b:\Restoremenow.txt")

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

    MsgBox(0, "Finish Restore", "Restore konnte erfolgreich zurück gesichert werden.")
    Exit

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

    ;FileDelete("b:\Restoremenow.cmd")
    ;DriveMapDel("r:")
    EndIf
    Until $msg = $GUI_EVENT_CLOSE
    EndFunc ;==>End Example

    [/autoit]


    hier mein Laptop.ini

    Spoiler anzeigen
  • Hallo maurice,

    probiere es einmal so:

    Spoiler anzeigen
    [autoit]

    #include <array.au3>
    #include <file.au3>
    #include <GUIConstantsEx.au3>

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

    Opt('MustDeclareVars', 1)
    Example()
    Func Example()

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

    Local $aboutitem, $helpmenu, $n1, $n2, $msg, $font, $var, $cfgfile, $ip, $s
    Local $file, $cfgfile, $filelist, $exititem, $section, $msgbox, $restore
    ;/ MAC TEIL
    Local $filename, $source_filename, $found, $array, $text, $macs, $filearray, $y, $j, $section1

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

    GUICreate("Info Fenster - Restore now", 300, 300) ; Fenster Balken

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

    $filelist = GUICtrlCreateMenu("&File")
    $exititem = GUICtrlCreateMenuItem("Exit", $filelist)
    $helpmenu = GUICtrlCreateMenu("&?")
    $aboutitem = GUICtrlCreateMenuItem("&About", $helpmenu)

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

    $font = "Arial"
    GUISetFont(11, 400, 3, $font) ; Font
    GUICtrlCreateLabel("Wählen Sie das passende Image", 11, 30)

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

    $n1 = GUICtrlCreateCombo("", 10, 50)

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

    $section = IniReadSection("laptop.ini", "section")
    For $i = 1 To UBound($section) - 1

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

    GUICtrlSetData($n1, IniRead("laptop.ini", "section", $i, ""))
    Next

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

    $n2 = GUICtrlCreateButton("Wiederherstellen", 10, 110, 120)

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

    ;DriveMapAdd("r:", "\\xyz\e$\xyz\Data\images\PC_laptops\laptop vat", 0, "login", "") ;<=====================

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

    GUICtrlSetState(-1, $GUI_FOCUS) ; the focus is on this button
    GUISetState()

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

    Do
    $msg = GUIGetMsg()
    Switch $msg
    ;Case $exititem
    Case $aboutitem
    GUISetFont(14, 400, 1, $font)
    GUICtrlCreateLabel("" & Chr(10) & Chr(10) & "" & Chr(10) & "Version 0.5", 10, 180, 320)
    Case $exititem
    ;Case $exititem, $GUI_EVENT_CLOSE
    Exit

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

    EndSwitch
    ;ExitLoop

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

    $ip = StringInStr(@IPAddress1, "192.168")
    $msg = GUIGetMsg()
    If $msg = $n2 Then
    $msgbox = MsgBox(1, "Achtung !", "Das Laptop model lautet: " & GUICtrlRead($n1) & Chr(10) & "Die zugewiesene IP-Adresse lautet: " & @IPAddress1 & Chr(10) & Chr(10) & "Klicken Sie < OK > zum Starten der Wiederherstellung " & Chr(10) & "Klicken Sie < Abbrechen > zum Abbrechen der Auswahl") ; anzeige gewähltes Image

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

    ; START MAC
    $filename = "ipconfig.txt"

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

    ; mit ipconfig Mac auslesen

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

    RunWait(@ComSpec & " /c ipconfig /all > " & $filename, "", @SW_HIDE)
    Dim $array
    _FileReadToArray($filename, $array)
    $text = _ArrayToString($array, ";")

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

    MsgBox(1, "", GUICtrlRead($n1)) ; uberprüfung des gewählten laptop
    $section1 = IniReadSection("laptop.ini", ""&GuiCtrlRead($n1)&"" )
    If @error Then
    MsgBox(4096, "Laptop: " & GUICtrlRead($n1), "Es ist ein Fehler aufgetreten. Warscheinlich keine INI Datei vorhanden.")
    Else
    _ArrayDisplay($section1)
    ;For $z=1 To UBound($section1)-1
    ; msgbox(1, "", $z) ; Only for TEST
    ;Next
    EndIf ; <================= bis hier ist alles in Ordnung

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

    $macs = StringRegExp($text, "(..-..-..-..-..-..)", 3)
    ;MsgBox(1, "Mac-Adresse", $text)
    _ArrayDisplay($macs)
    ;Dim $filearray
    ;<============= von hier
    For $y = 1 To UBound($section1) - 1
    For $j = 0 To UBound($macs) - 1

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

    ; If StringInStr($section1[$y], $macs[$j]) Then
    If $section1[$y][1] = $macs[$j] Then
    $found = $macs[$j]
    ExitLoop
    EndIf
    Next
    Next
    ;<=============== bis hier

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

    ; Ausgabe
    If $found <> "" Then
    MsgBox(0, "MAC-Adresse gefunden", "Ihre MAC-Adresse wurde gefunden (" & $found & ")")
    Else
    MsgBox(0, "MAC-Adresse nicht gefunden", "Ihre MAC-Adresse wurde nicht gefunden.")
    FileDelete($filename)
    Exit
    EndIf

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

    ; temporäre Datei löschen
    FileDelete($filename)
    ; STOP MAC

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

    If $msgbox = 2 Then Exit

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

    DriveMapAdd("r:", "\\xyz\e$\xyz\Data\images\PC_laptops\laptop vat", 0, "login", "")
    Sleep(Random(1000, 3000))

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

    $cfgfile = FileOpen("b:\" & GUICtrlRead($n1) & ".cfg", 1)
    FileWriteLine($cfgfile, "; * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *")
    FileWriteLine($cfgfile, "; * -- Restore Script for Laptop.ini | Time " & @HOUR & ":" & @MIN & ":" & @SEC & " ---> Datum " & @MDAY & "." & @MON & "." & @YEAR & " -- *")
    FileWriteLine($cfgfile, "; * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *")
    FileWriteLine($cfgfile, "mouse=no")
    FileWriteLine($cfgfile, "filesystem=ntfs")
    FileWriteLine($cfgfile, "disk=0")
    FileWriteLine($cfgfile, "main_part=1")
    FileWriteLine($cfgfile, "def_level=6")
    FileWriteLine($cfgfile, "quit=nobadsector")
    FileWriteLine($cfgfile, "automatic_naming=yes")
    FileWriteLine($cfgfile, "file=r:\" & GUICtrlRead($n1))
    FileClose($cfgfile)
    Sleep(Random(1000, 2000))

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

    $file = FileOpen("b:\Restoremenow.cmd", 1)
    FileWriteLine($file, "REM * * * * * * * * * * * * * * * * * * * * * * *")
    FileWriteLine($file, "REM * --- Zeit " & @HOUR & ":" & @MIN & ":" & @SEC & " -> Datum " & @MDAY & "." & @MON & "." & @YEAR & " --- *")
    FileWriteLine($file, "REM * * * * * * * * * * * * * * * * * * * * * * *")
    FileWriteLine($file, "x:\programs\imager\spartwin.ex_e -r -f b:\" & GUICtrlRead($n1) & ".cfg")

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

    FileClose($file)

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

    Sleep(Random(1000, 2000))

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

    RunWait("b:\Restoremenow.cmd", "", @SW_MAXIMIZE)

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

    ;Run("b:\Restoremenow.cmd", "", @SW_MAXIMIZE)
    FileMove("b:\" & GUICtrlRead($n1) & ".cfg", "b:\" & GUICtrlRead($n1) & ".txt")
    FileMove("b:\Restoremenow.cmd", "b:\Restoremenow.txt")

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

    MsgBox(0, "Finish Restore", "Restore konnte erfolgreich zurück gesichert werden.")
    Exit

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

    ;FileDelete("b:\Restoremenow.cmd")
    ;DriveMapDel("r:")
    EndIf
    Until $msg = $GUI_EVENT_CLOSE
    EndFunc ;==>Example

    [/autoit]


    Stellen an denen ich wichtige Änderungen vorgenommen habe sind mit ;<========== gekennzeichnet

    Viel Spass damit,

    mfg (Auto)Bert

  • AutoBert Danke dir vielmals :D

    Warum muss ich 2 -3 mal die Buttons meiner Anwendung betätigen damit diese reagieren
    habe ich noch weitere fehler in meinem Script ?.

    Besten und vielendank !