Herzlichen Dank für eure Tips!
Besonders das mit den Schnittmengen - genau das was ich gesucht habe!
Nur die Ergebnisse erstaunen mich, wieso bekomme ich in "Unterschiede 2" einfach alle Keys aufgelistet? Denke dass ist einfach noch bisschen zu hoch für mich ![]()
Im Attachement ist der Script, das Textfile sowie ein Sample-Regfile.
Wünschenswert wäre hier gewesen, wenn ich in $diff2 alle Regkeys zum löschen erhhalten hätte.
[autoit]#include <array.au3>
#include <File.au3>
; #### Registry in ein Array einlesen
Global $aFile
Global $arSubKey
Global $arSubKey2
Dim $arSubKey[1] = [0]
$i = 1
While 1
$subkey = RegEnumKey('HKEY_CURRENT_USER\Software\blubb', $i)
If @error Then ExitLoop
$arSubKey[0] += 1
ReDim $arSubKey[UBound($arSubKey)+1]
$arSubKey[UBound($arSubKey)-1] = $subkey
$i += 1
WEnd
;_ArrayDisplay($arSubKey)
; #### Zeilen in Textfile in ein Array einlesen
Local $aFile, $file = @ScriptDir & '\test.txt' ; der Dateipfad
_FileReadToArray($file, $aFile)
For $i = 1 To UBound($aFile) -1
Next
;_ArrayDisplay($aFile)
; #### Nun die beiden Arrays vergleichen
[/autoit][autoit][/autoit][autoit]$ret = _GetIntersection($aFile, $arSubKey, 0, '1')
;$ret = _GetIntersection($arSubKey, $aFile, 0, ' ')
$diff1 = ''
$diff2 = ''
If Not @error Then
For $i = 0 To UBound($ret) -1
If $ret[$i][1] <> '' Then $diff1 &= $ret[$i][1] & ' ; '
If $ret[$i][2] <> '' Then $diff2 &= $ret[$i][2] & ' ; '
Next
EndIf
MsgBox(0, '', 'Unterschiede 1: ' & $diff1 & @LF & 'Unterschiede 2: ' & $diff2)
;==================================================================================================
; Function Name: _GetIntersection($Set1, $Set2 [, $GetAll=0 [, $Delim=Default]])
; Description:: Detect from 2 sets
; - Intersection (elements are contains in both sets)
; - Difference 1 (elements are contains only in $Set1)
; - Difference 2 (elements are contains only in $Set2)
; Parameter(s): $Set1 set 1 (1D-array or delimited string)
; $Set2 set 2 (1D-array or delimited string)
; optional: $GetAll 0 - only one occurence of every different element are shown (Default)
; 1 - all elements of differences are shown
; optional: $Delim Delimiter for strings (Default use the separator character set by Opt("GUIDataSeparatorChar") )
; Return Value(s): Succes 2D-array [i][0]=Intersection
; [i][1]=Difference 1
; [i][2]=Difference 2
; Failure -1 @error set, that was given as array, is'nt 1D-array
; Note: Comparison is case-sensitiv! - i.e. Number 9 is different to string '9'!
; Author(s): BugFix ([email='bugfix@autoit.de'][/email])
;==================================================================================================
Func _GetIntersection(ByRef $Set1, ByRef $Set2, $GetAll=0, $Delim=Default)
Local $o1 = ObjCreate("System.Collections.ArrayList")
Local $o2 = ObjCreate("System.Collections.ArrayList")
Local $oUnion = ObjCreate("System.Collections.ArrayList")
Local $oDiff1 = ObjCreate("System.Collections.ArrayList")
Local $oDiff2 = ObjCreate("System.Collections.ArrayList")
Local $tmp, $i
If $GetAll <> 1 Then $GetAll = 0
If $Delim = Default Then $Delim = Opt("GUIDataSeparatorChar")
If Not IsArray($Set1) Then
If Not StringInStr($Set1, $Delim) Then
$o1.Add($Set1)
Else
$tmp = StringSplit($Set1, $Delim)
For $i = 1 To UBound($tmp) -1
$o1.Add($tmp[$i])
Next
EndIf
Else
If UBound($Set1, 0) > 1 Then Return SetError(1,0,-1)
For $i = 0 To UBound($Set1) -1
$o1.Add($Set1[$i])
Next
EndIf
If Not IsArray($Set2) Then
If Not StringInStr($Set2, $Delim) Then
$o2.Add($Set2)
Else
$tmp = StringSplit($Set2, $Delim)
For $i = 1 To UBound($tmp) -1
$o2.Add($tmp[$i])
Next
EndIf
Else
If UBound($Set2, 0) > 1 Then Return SetError(1,0,-1)
For $i = 0 To UBound($Set2) -1
$o2.Add($Set2[$i])
Next
EndIf
For $tmp In $o1
If $o2.Contains($tmp) And Not $oUnion.Contains($tmp) Then $oUnion.Add($tmp)
Next
For $tmp In $o2
If $o1.Contains($tmp) And Not $oUnion.Contains($tmp) Then $oUnion.Add($tmp)
Next
For $tmp In $o1
If $GetAll Then
If Not $oUnion.Contains($tmp) Then $oDiff1.Add($tmp)
Else
If Not $oUnion.Contains($tmp) And Not $oDiff1.Contains($tmp) Then $oDiff1.Add($tmp)
EndIf
Next
For $tmp In $o2
If $GetAll Then
If Not $oUnion.Contains($tmp) Then $oDiff2.Add($tmp)
Else
If Not $oUnion.Contains($tmp) And Not $oDiff2.Contains($tmp) Then $oDiff2.Add($tmp)
EndIf
Next
Local $UBound[3] = [$oDiff1.Count,$oDiff2.Count,$oUnion.Count], $max = 1
For $i = 0 To UBound($UBound) -1
If $UBound[$i] > $max Then $max = $UBound[$i]
Next
Local $aOut[$max][3]
If $oUnion.Count > 0 Then
$i = 0
For $tmp In $oUnion
$aOut[$i][0] = $tmp
$i += 1
Next
EndIf
If $oDiff1.Count > 0 Then
$i = 0
For $tmp In $oDiff1
$aOut[$i][1] = $tmp
$i += 1
Next
EndIf
If $oDiff2.Count > 0 Then
$i = 0
For $tmp In $oDiff2
$aOut[$i][2] = $tmp
$i += 1
Next
EndIf
Return $aOut
EndFunc ;==>_GetIntersection
; #### Werte in Registry löschen, die nicht im Textfile enthalten sind
Vielleicht erkennt jemand ja auf einen blick, wie man das anpassen müsste, um eine variable mit allen zu löschenden Keys zu erhalten ![]()
Das löschen müsste dann ja so gehen:
For $i = 0 To UBound($diff2) -1
$regDelete = RegDelete($diff2[$i])
Next