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
#Include <array.au3>
#include <file.au3>
#include <GUIConstantsEx.au3>
Opt('MustDeclareVars', 1)
Example()
Func Example()
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
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)
$font = "Arial"
GUISetFont(11, 400, 3, $font) ; Font
GUICtrlCreateLabel("Wählen Sie das passende Image", 11, 30)
$n1=GUICtrlCreateCombo("", 10, 50)
[/autoit] [autoit][/autoit] [autoit]$section=IniReadSection("laptop.ini", "section")
For $i=1 To UBound($section)-1
GuiCtrlSetData($n1, IniRead("laptop.ini", "section", $i, ""))
Next
$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()
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
EndSwitch
;ExitLoop
$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
; START MAC
$filename = "ipconfig.txt"
; mit ipconfig Mac auslesen
[/autoit] [autoit][/autoit] [autoit]RunWait(@ComSpec & " /c ipconfig /all > " & $filename, "", @SW_HIDE)
Dim $array
_FileReadToArray($filename, $array)
$text = _ArrayToString($array, ";")
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
$macs = StringRegExp($text, "(..-..-..-..-..-..)", 3)
msgbox(1, "", $text)
Dim $filearray
[/autoit] [autoit][/autoit] [autoit]For $y=0 To UBound($filearray)-1
For $j=0 to ubound($macs)-1
if stringinstr($filearray[$y],$macs[$j]) Then
$found = $macs[$j]
ExitLoop
EndIf
Next
Next
; 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
; temporäre Datei löschen
FileDelete($filename)
; STOP MAC
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))
$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))
$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")
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")
MsgBox(0, "Finish Restore", "Restore konnte erfolgreich zurück gesichert werden.")
Exit
;FileDelete("b:\Restoremenow.cmd")
;DriveMapDel("r:")
EndIf
Until $msg = $GUI_EVENT_CLOSE
EndFunc ;==>End Example
hier mein Laptop.ini
Spoiler anzeigen
[section]
1=IBM_Muster
2=IBM_Z60M
3=IBM_X200
4=IBM_X40
5=IBM_X41
[IBM_Muster]
1=00-0C-29-3B-99-E9
2=00-0C-29-C2-1E-3F
3=00-00-00-C0-00-00
[IBM_Z60M]
1=00-16-36-0B-63-9A
2=00-00-00-C0-00-00
[IBM_X200]
1=00-00-00-00-00-00
2=00-00-00-00-00-00
[IBM_X40]
1=00-0A-E4-3E-30-13
2=00-00-00-00-00-00
[IBM_X41]
1=00-16-D3-33-C3-47
2=00-00-00-00-00-00
3=00-00-00-00-00-00
4=00-00-00-00-00-00
5=00-00-00-00-00-00
6=00-00-00-00-00-00
7=00-00-00-00-00-00
8=00-00-00-00-00-00
Alles anzeigen