Alle Unterschlüssel eines Registry Pfades herausbekommen

  • Hi @all

    Ich habe mal ne Frage
    Ich will alle "Dateien" eines Registry Ordners Herausfinden mit des Types REG_SZ

    Mit RegEnumVal kann man die Namen einlesen allerdings braucht man ein Instance, die ANzahl dieser Instanzen kann aber verschieden sein somit habe ich ein Problem

    In der Hilfe habe ich noch keione Regedit befehl dazugefunden

    Ich hoffe jemand hat eine Lösung

  • Ah Okay danke habs hinbekommen mit ner while schlife imemr hochzählen und wenn @error dann exitloop und in array abgespeichert und mit redim erhöht
    danke

  • Hier ein Code Ausschnitt von SIC2, um die installierte Software (für alle Benutzer) von System per Registry auszulesen (in der unbeliebten Commandline Version :D ), ohne "Updates anzeigen"!

    Spoiler anzeigen
    [autoit]


    ;Coded by UEZ 2009
    #AutoIt3Wrapper_Change2CUI=y
    #AutoIt3Wrapper_UseUpx=n
    #AutoIt3Wrapper_UseX64=n
    #include <array.au3>
    Global $server = "localhost"
    If $CmdLine[0] > 0 Then $server = $CmdLine[1]

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

    $objWMIService = ObjGet("winmgmts:{impersonationLevel = impersonate}!\\" & $server & "\root\cimv2")

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

    ConsoleWrite(@CRLF & "Installed software on " & $server & @CRLF & @CRLF)
    Software($server)

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

    Func Software($srv) ; registry read version 2
    Local $function_name = "Software"
    Local $objReg, $HKLM, $BaseKey, $BaseKey64, $server, $arrSubKeys, $SubKey, $Value, $objRegService, $chk_nr, $chk_url, $chk_sc
    Local $software, $Key, $key_value, $SW_DisplayName, $SW_DisplayVersion, $SW_Publisher, $SW_InstallDate, $line, $TimeStamp
    Local $filename_sw = $function_name & "_" & $srv
    Local $filename_error_current = $function_name & "_" & $srv & "_error.log"
    $HKLM = 0x80000002
    $BaseKey = "Software\Microsoft\Windows\CurrentVersion\Uninstall\"
    $BaseKey64 = "SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\"
    If @OSArch = "X64" And ($srv = @ComputerName Or _
    $srv = "localhost" Or _
    $srv = @IPAddress1 Or _
    $srv = @IPAddress2 Or _
    $srv = @IPAddress3 Or _
    $srv = @IPAddress4) Then
    $i = 1
    While 1
    $key = RegEnumKey("HKEY_LOCAL_MACHINE\" & $BaseKey, $i)
    If @error <> 0 Then ExitLoop
    $key_value = RegRead("HKEY_LOCAL_MACHINE\" & $BaseKey & "\" & $key, "DisplayName")
    $chk_sc = RegRead("HKEY_LOCAL_MACHINE\" & $BaseKey & "\" & $key, "SystemComponent")
    $chk_url = RegRead("HKEY_LOCAL_MACHINE\" & $BaseKey & "\" & $key, "MoreInfoURL")
    $chk_nr = RegRead("HKEY_LOCAL_MACHINE\" & $BaseKey & "\" & $key, "NoRemove")
    If $key_value <> "" And _
    StringIsASCII($key_value) <> 0 And _
    $key_value <> "Security Update for" And _
    $key_value <> "Hotfix for" And _
    $key_value <> "Update for Office" And _
    $key_value <> "Windows 2000 Hotfix" And _
    StringInStr(StringLower($key), StringLower("InstallShield_")) = 0 And _
    StringInStr(StringLower($chk_url), StringLower("http://support.microsoft.com/kb/")) = 0 And _
    $chk_nr <> 1 And $chk_sc <> 1 Then
    $SW_DisplayName = StringStripWS($key_value, 7)
    $SW_Publisher = RegRead("HKEY_LOCAL_MACHINE\" & $BaseKey & "\" & $key, "Publisher")
    $SW_InstallDate = RegRead("HKEY_LOCAL_MACHINE\" & $BaseKey & "\" & $key, "InstallDate")
    $SW_DisplayVersion = RegRead("HKEY_LOCAL_MACHINE\" & $BaseKey & "\" & $key, "DisplayVersion")
    $software &= $srv & ";" & $SW_DisplayName & ";" & $SW_DisplayVersion & ";" & $SW_Publisher & ";" & $SW_InstallDate & ";" & @CRLF
    EndIf
    $i += 1
    WEnd

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

    $i = 1
    While 1
    $key = RegEnumKey("HKEY_LOCAL_MACHINE64\" & $BaseKey, $i)
    If @error <> 0 Then ExitLoop
    $key_value = RegRead("HKEY_LOCAL_MACHINE64\" & $BaseKey & "\" & $key, "DisplayName")
    $chk_sc = RegRead("HKEY_LOCAL_MACHINE64\" & $BaseKey & "\" & $key, "SystemComponent")
    $chk_url = RegRead("HKEY_LOCAL_MACHINE64\" & $BaseKey & "\" & $key, "MoreInfoURL")
    $chk_nr = RegRead("HKEY_LOCAL_MACHINE64\" & $BaseKey & "\" & $key, "NoRemove")
    If $key_value <> "" And _
    StringIsASCII($key_value) <> 0 And _
    $key_value <> "Security Update for" And _
    $key_value <> "Hotfix for" And _
    $key_value <> "Update for Office" And _
    $key_value <> "Windows 2000 Hotfix" And _
    StringInStr(StringLower($key), StringLower("InstallShield_")) = 0 And _
    StringInStr(StringLower($chk_url), StringLower("http://support.microsoft.com/kb/")) = 0 And _
    $chk_nr <> 1 And $chk_sc <> 1 Then
    $SW_DisplayName = StringStripWS($key_value, 7)
    $SW_Publisher = RegRead("HKEY_LOCAL_MACHINE64\" & $BaseKey & "\" & $key, "Publisher")
    $SW_InstallDate = RegRead("HKEY_LOCAL_MACHINE64\" & $BaseKey & "\" & $key, "InstallDate")
    $SW_DisplayVersion = RegRead("HKEY_LOCAL_MACHINE64\" & $BaseKey & "\" & $key, "DisplayVersion")
    $software &= $srv & ";" & $SW_DisplayName & ";" & $SW_DisplayVersion & ";" & $SW_Publisher & ";" & $SW_InstallDate & ";" & @CRLF
    EndIf
    $i += 1
    WEnd
    Else
    If StringLower(@OSVersion) <> StringLower("WIN_2000") Then
    $objWMILocator = ObjCreate("WbemScripting.SWbemLocator")
    $objRegService = $objWMILocator.ConnectServer($srv, "\root\default", "", "", "", "", 0x80)
    $objReg = $objRegService.Get("StdRegProv")
    Else
    $objReg = ObjGet("winmgmts:{impersonationLevel=impersonate}!\\" & $srv & "\root\default:StdRegProv")
    EndIf

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

    If IsObj($objReg) Then
    $objReg.EnumKey($HKLM, $BaseKey, $arrSubKeys)
    For $SubKey In $arrSubKeys
    $SW_DisplayName = ""
    $SW_DisplayVersion = ""
    $SW_Publisher = ""
    $SW_InstallDate = ""
    $Key = $objReg.GetStringValue($HKLM, $BaseKey & $SubKey, "DisplayName", $Value)
    $objReg.GetDWORDValue($HKLM, $BaseKey & $SubKey, "NoRemove", $chk_nr)
    $objReg.GetDWORDValue($HKLM, $BaseKey & $SubKey, "SystemComponent", $chk_sc)
    $objReg.GetStringValue($HKLM, $BaseKey & $SubKey, "MoreInfoURL", $chk_url)
    If $Key <> 0 Or StringLeft($SubKey, 2) = "KB" Or StringLeft($SubKey, 1) = "Q" Then
    $Key = $objReg.GetStringValue($HKLM, $BaseKey & $SubKey, "QuietDisplayName", $Value)
    EndIf
    If $Value <> "" And StringIsASCII($Value) <> 0 _
    And $Key = 0 And StringInStr(StringLower($Value), StringLower("Security Update for")) = 0 _
    And StringInStr(StringLower($Value), StringLower("Update for Windows")) = 0 _
    And StringInStr(StringLower($Value), StringLower("Hotfix for")) = 0 _
    And StringInStr(StringLower($Value), StringLower("Update for Office")) = 0 _
    And StringInStr(StringLower($SubKey), StringLower("InstallShield_")) = 0 _
    And StringInStr(StringLower($Value), StringLower("Windows 2000 Hotfix")) = 0 _
    And StringInStr(StringLower($chk_url), StringLower("http://support.microsoft.com/kb/")) = 0 _
    And $chk_nr <> 1 _
    And $chk_sc <> 1 Then
    $SW_DisplayName = $Value

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

    $Key = $objReg.GetStringValue($HKLM, $BaseKey & $SubKey, "DisplayVersion", $Value)
    If $Value <> "" And StringIsASCII($Value) <> 0 Then
    $SW_DisplayVersion = StringStripWS($Value, 7)
    EndIf

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

    $Key = $objReg.GetStringValue($HKLM, $BaseKey & $SubKey, "Publisher", $Value)
    If $Value <> "" And StringIsASCII($Value) <> 0 Then
    $SW_Publisher = StringStripWS($Value, 7)
    EndIf

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

    $Key = $objReg.GetStringValue($HKLM, $BaseKey & $SubKey, "InstallDate", $Value)
    If $Value <> "" And StringIsASCII($Value) <> 0 Then $SW_InstallDate = $Value
    $line = $srv & ";" & $SW_DisplayName & ";" & $SW_DisplayVersion & ";" & $SW_Publisher & ";" & $SW_InstallDate & ";" & @CRLF
    $software &= $line
    EndIf
    Next

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

    Dim $arrSubKeys
    $objReg.EnumKey($HKLM, $BaseKey64, $arrSubKeys)
    If UBound($arrSubKeys) > 0 Then
    For $SubKey In $arrSubKeys
    $SW_DisplayName = ""
    $SW_DisplayVersion = ""
    $SW_Publisher = ""
    $SW_InstallDate = ""
    $Key = $objReg.GetStringValue($HKLM, $BaseKey64 & $SubKey, "DisplayName", $Value)
    $objReg.GetDWORDValue($HKLM, $BaseKey64 & $SubKey, "NoRemove", $chk_nr)
    $objReg.GetDWORDValue($HKLM, $BaseKey64 & $SubKey, "SystemComponent", $chk_sc)
    $objReg.GetStringValue($HKLM, $BaseKey64 & $SubKey, "MoreInfoURL", $chk_url)
    If $Key <> 0 Or StringLeft($SubKey, 2) = "KB" Or StringLeft($SubKey, 1) = "Q" Then
    $Key = $objReg.GetStringValue($HKLM, $BaseKey64 & $SubKey, "QuietDisplayName", $Value)
    EndIf
    If $Value <> "" And StringIsASCII($Value) <> 0 _
    And $Key = 0 And StringInStr(StringLower($Value), StringLower("Security Update for")) = 0 _
    And StringInStr(StringLower($Value), StringLower("Update for Windows")) = 0 _
    And StringInStr(StringLower($Value), StringLower("Hotfix for")) = 0 _
    And StringInStr(StringLower($Value), StringLower("Update for Office")) = 0 _
    And StringInStr(StringLower($SubKey), StringLower("InstallShield_")) = 0 _
    And StringInStr(StringLower($Value), StringLower("Windows 2000 Hotfix")) = 0 _
    And StringInStr(StringLower($chk_url), StringLower("http://support.microsoft.com/kb/")) = 0 _
    And $chk_nr <> 1 _
    And $chk_nr <> 1 Then
    $SW_DisplayName = $Value

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

    $Key = $objReg.GetStringValue($HKLM, $BaseKey64 & $SubKey, "DisplayVersion", $Value)
    If $Value <> "" And StringIsASCII($Value) <> 0 Then
    $SW_DisplayVersion = StringStripWS($Value, 7)
    EndIf

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

    $Key = $objReg.GetStringValue($HKLM, $BaseKey64 & $SubKey, "Publisher", $Value)
    If $Value <> "" And StringIsASCII($Value) <> 0 Then
    $SW_Publisher = StringStripWS($Value, 7)
    EndIf

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

    $Key = $objReg.GetStringValue($HKLM, $BaseKey64 & $SubKey, "InstallDate", $Value)
    If $Value <> "" And StringIsASCII($Value) <> 0 Then $SW_InstallDate = $Value
    $line = $srv & ";" & $SW_DisplayName & ";" & $SW_DisplayVersion & ";" & $SW_Publisher & ";" & $SW_InstallDate & ";" & @CRLF
    $software &= $line
    EndIf
    Next
    EndIf
    EndIf
    EndIf
    ConsoleWrite($software & @CRLF)
    EndFunc ;==>Software

    [/autoit]

    Für Remote Systeme muss der eigene Account berechtigt und die Ports für die WMI Abfrage müssen offen sein (keine Errorhandling in dem Beispiel)!

    Vielleicht ist es auch für jemanden nützlich!

    UEZ

  • Und mein alter Registry-Viewer ;)

    Spoiler anzeigen
    [autoit]

    #Region ;**** Directives created by AutoIt3Wrapper_GUI ****
    #AutoIt3Wrapper_icon=..\Eigene Bilder\Bilder\favi\favicon.ico
    #AutoIt3Wrapper_outfile=regView.exe
    #AutoIt3Wrapper_Res_Description=Registry Viewer
    #AutoIt3Wrapper_AU3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6
    #EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

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

    ; #SCRIPT# ====================================================================================================================
    ; Name...........: RegView
    ; Description ...: Zeight die Registry an
    ; Author ........: Prog@ndy
    ; ===============================================================================================================================

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

    #include <GuiConstantsEx.au3>
    #include <Constants.au3>
    #include <GuiTreeView.au3>
    #include <GuiListView.au3>
    #include <WindowsConstants.au3>

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

    Opt('MustDeclareVars', 1)

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

    $Debug_TV = False ; Check ClassName being passed to functions, set to True and use a handle to another control to see it work

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

    Global $hTreeView,$Progress,$ListView,$hListView, $inKey

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

    _Main()

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

    Func _Main()

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

    Local $GUI, $hItem, $OpenKey, $nMsg
    Local $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS)
    $GUI = GUICreate("RegView", 800, 610)

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

    $hTreeView = _GUICtrlTreeView_Create($GUI, 2, 35, 350, 550, $iStyle, $WS_EX_CLIENTEDGE)
    $Progress = GUICtrlCreateProgress(2,587,100,10)
    $inKey = GUICtrlCreateInput("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Internet Settings",110,587,300,20)
    $OpenKey = GUICtrlCreateButton("Open Key",412,587,90,20)
    GUISetState()

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

    GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

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

    _GUICtrlTreeView_BeginUpdate($hTreeView)
    $hItem = _GUICtrlTreeView_Add($hTreeView,0,"HKLM")
    _GUICtrlTreeView_AddChild($hTreeView,$hItem,RegEnumKey("HKLM",1))
    $hItem = _GUICtrlTreeView_Add($hTreeView,0,"HKU")
    _GUICtrlTreeView_AddChild($hTreeView,$hItem,RegEnumKey("HKU",1))
    $hItem = _GUICtrlTreeView_Add($hTreeView,0,"HKCU")
    _GUICtrlTreeView_AddChild($hTreeView,$hItem,RegEnumKey("HKCU",1))
    $hItem = _GUICtrlTreeView_Add($hTreeView,0,"HKCR")
    _GUICtrlTreeView_AddChild($hTreeView,$hItem,RegEnumKey("HKCR",1))
    $hItem = _GUICtrlTreeView_Add($hTreeView,0,"HKCC")
    _GUICtrlTreeView_AddChild($hTreeView,$hItem,RegEnumKey("HKCC",1))
    _GUICtrlTreeView_EndUpdate($hTreeView)
    $ListView = GUICtrlCreateListView("Key|Value|Type",355,35,440,550)
    $hListView = GUICtrlGetHandle($ListView)
    _GUICtrlListView_SetColumnWidth($hListView,0,150)
    _GUICtrlListView_SetColumnWidth($hListView,1,150)
    _GUICtrlListView_SetColumnWidth($hListView,2,$LVSCW_AUTOSIZE_USEHEADER)
    ; Loop until user exits
    Do
    $nMsg = GUIGetMsg()
    If $nMsg = $OpenKey Then _FillListView($hListView,GUICtrlRead($inKey))
    Until $nMsg = $GUI_EVENT_CLOSE
    GUIDelete()
    EndFunc ;==>_Main

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

    Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTreeview, $tNMTREEVIEW, $sKEy,$sProp,$sVal,$i,$type,$item,$tNMITEMACTIVATE
    $hWndTreeview = $hTreeView
    If Not IsHWnd($hTreeView) Then $hWndTreeview = GUICtrlGetHandle($hTreeView)

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

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "IDFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    Switch $hWndFrom
    Case $hWndTreeview
    $tNMTREEVIEW = DllStructCreate($tagNMTREEVIEW ,$ilParam)
    $item = DllStructGetData($tNMTREEVIEW,"NewhItem")
    Switch $iCode
    Case $TVN_ITEMEXPANDING, $TVN_ITEMEXPANDINGW
    If _GUICtrlTreeView_GetChildCount($hWndFrom,$item) <= 1 Then
    GUICtrlSetData($Progress,0)
    _GUICtrlTreeView_BeginUpdate($hWndFrom)
    $sKEy = _GetTreeKeyPath($hWndFrom,$item)
    ConsoleWrite($sKEy & @CRLF)
    ConsoleWrite( @error & @CRLF)
    $i = 2
    Local $sRead, $citem
    While 1
    If Mod($i,100) == 0 Then GUICtrlSetData($Progress,Mod(GUICtrlRead($Progress)+10,100))
    $sRead = RegEnumKey($sKEy,$i)
    If @error Then ExitLoop
    $citem = _GUICtrlTreeView_AddChild($hWndFrom,$item,$sRead)
    $sRead = RegEnumKey($sKEy&"\"&$sRead,1)
    If Not @error Then _GUICtrlTreeView_AddChild($hWndFrom,$citem,$sRead)
    $i += 1
    WEnd
    GUICtrlSetData($Progress,150)
    _GUICtrlTreeView_EndUpdate($hWndFrom)
    EndIf
    Case $TVN_SELCHANGED, $TVN_SELCHANGEDW
    $sKEy = _GetTreeKeyPath($hWndFrom,$item)
    ConsoleWrite($sKEy & @CRLF)
    _FillListView($hListView,$sKEy)
    EndSwitch
    Case $hListView
    ;~ $tNMITEMACTIVATE = DllStructCreate($tagNMITEMACTIVATE ,$ilParam)
    ;~ $item = DllStructGetData($tNMITEMACTIVATE,"iItem")
    Switch $iCode
    Case $NM_DBLCLK
    $item = _GUICtrlListView_GetSelectedIndices($hWndFrom)
    ;~ ConsoleWrite($item & _GUICtrlListView_GetItemTextString($hWndFrom) & @CRLF)
    If $item > -1 And $item <> "" Then InputBox("Text","Value of Property (no edit)",_GUICtrlListView_GetItemText($hWndFrom,$item,1))
    EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
    EndFunc ;==>WM_NOTIFY

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

    Func _GetTreeKeyPath($hWndFrom,$item)
    Local $hParent,$sKEy
    $hParent = _GUICtrlTreeView_GetParentHandle($hWndFrom,$item)
    $sKEy = _GUICtrlTreeView_GetText($hWndFrom,$item)
    While $hParent
    $sKEy = _GUICtrlTreeView_GetText($hWndFrom,$hParent) & "\" & $sKEy
    $hParent = _GUICtrlTreeView_GetParentHandle($hWndFrom,$hParent)
    WEnd
    Return $sKEy
    EndFunc

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

    Func _FillListView($hListView,$sKEy)
    Local $i, $type, $sVal,$sProp
    _GUICtrlListView_BeginUpdate($hListView)
    _GUICtrlListView_DeleteAllItems($hListView)
    $i = 0
    $type = ""
    GUICtrlCreateListViewItem("(Default)|"&RegRead($sKEy,"")&"|$REG_SZ",$ListView)
    While 1
    $i += 1
    ConsoleWrite($i & @CRLF)
    $sProp = RegEnumVal($sKEy,$i)
    If @error Then
    ExitLoop
    ElseIf $sProp == "" Then
    ContinueLoop
    EndIf
    $sVal = RegRead($sKEy,$sProp)
    Switch @extended
    Case 0
    $type = "$REG_NONE"
    Case 1
    $type = "$REG_SZ"
    Case 2
    $type = "$REG_EXPAND_SZ"
    Case 3
    $type = "$REG_BINARY"
    Case 4
    $type = "$REG_DWORD"
    Case 5
    $type = "$REG_DWORD_BIG_ENDIAN"
    Case 6
    $type = "$REG_LINK"
    Case 7
    $type = "$REG_MULTI_SZ"
    Case 8
    $type = "$REG_RESOURCE_LIST"
    Case 9
    $type = "$REG_FULL_RESOURCE_DESCRIPTOR"
    Case 10
    $type = "$REG_RESOURCE_REQUIREMENTS_LIST"
    EndSwitch
    ;~ If $sProp == "" Then $sProp = "(Default)"
    GUICtrlCreateListViewItem($sProp&"|"&$sVal&"|"&$type,$ListView)
    WEnd
    _GUICtrlListView_EndUpdate($hListView)
    GUICtrlSetData($inKey,$sKEy)
    EndFunc

    [/autoit]