Jump to content
Sign in to follow this  
frankpintosr

How do I select all vaules under a registry key?

Recommended Posts

frankpintosr

I have a script which searches the registry and lists all matching keys. I need it to also list all values under those keys. Here is and exmample of a key that is returned:

HKEY_Users\S-1-5-21-1316817595-248915221-3852222622-1011\Software\ODBC\ODBC.INI\Frank User DSN\Driver = C:\WINDOWS\System32\odbcjt32.dll

I also want to capture all the values under the key which is found. So I need to have:

HKEY_Users\S-1-5-21-1316817595-248915221-3852222622-1011\Software\ODBC\ODBC.INI\Frank User DSN\ All Values Listed Here

This is what is under that key now, I am trying to export all these to a file:

Key Name: HKEY_USERS\S-1-5-21-1316817595-248915221-3852222622-1011\Software\ODBC\ODBC.INI\Frank User DSN

Class Name: <NO CLASS>

Last Write Time: 5/1/2008 - 3:07 PM

Value 0

Name: Driver

Type: REG_SZ

Data: C:\WINDOWS\System32\odbcjt32.dll

Value 1

Name: DBQ

Type: REG_SZ

Data: C:\Documents and Settings\xp-fpinto1\My Documents\doc1.mdb

Value 2

Name: Description

Type: REG_SZ

Data: Frank User DSN

Value 3

Name: DriverId

Type: REG_DWORD

Data: 0x19

Value 4

Name: FIL

Type: REG_SZ

Data: MS Access;

Value 5

Name: PWD

Type: REG_SZ

Data: password

Value 6

Name: SafeTransactions

Type: REG_DWORD

Data: 0x0

Value 7

Name: UID

Type: REG_SZ

Data: frank

Here is the code for the script, several of you have helped me get this far, thank you. This is the last piece I need and then, DONE!!

; Script Start - Add your code below here

#include <GUIConstants.au3>
#RequireAdmin
$SearchKey = "HKEY_Users"
$SearchString = "ODBC"

$Timer = TimerInit()
$Results = _RegSearch($SearchKey, $SearchString)
$Timer = TimerDiff($Timer) / 1000
MsgBox(64, "_RegSearch() Test", "Results of searching registry:" & @CRLF & _
        "In: " & $SearchKey & @CRLF & _
        "For: " & $SearchString & @CRLF & _
        "Time taken (in seconds): " & $Timer & @CRLF & _
        "---------------------------------------" & @CRLF & _
        $Results)
$split = StringSplit($Results, @LF)
For $X = 1 to $split[0]
FileWriteLine("c:\userinfo.txt", $split[$X])
Next

;This is the code I am trying to list the values from each key here, but it does not even produce a msgbox
For $a= 1 to 100
           $Allkeys = RegEnumVal($Results, $a)
          If @error <> 0 then ExitLoop
        MsgBox(4096, "_RegSearch() Test", "Results of searching registry:" & @CRLF & _
        "In: " & $SearchKey & @CRLF & _
        "For: " & $SearchString & @CRLF & _
        "Time taken (in seconds): " & $Timer & @CRLF & _
        "---------------------------------------" & @CRLF & _
        $Allkeys)
    Next


;*****************************************************
; Function _RegSearch($startkey, $searchval)
;   Performs a recursive search of the registry
;    Starting at $sStartKey, looking for $sSearchVal
; Returns a string containing a list of key names and values.
;   If a key name matches, it is listed as a reg path with trailing backslash:
;    i.e. HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\
;   If a value name matches, it is listed as a reg path without trailing backslash:
;    i.e. HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WallPaperDir
;   If the data matches, the format is path = data:
;      i.e. HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\WallPaperDir = %SystemRoot%\Web\Wallpaper
;*****************************************************
Func _RegSearch($startkey, $searchval)
    Local $v, $val, $k, $key, $found = ""
    
  ; This loop checks values
    $v = 1
    While 1
        $val = RegEnumVal($startkey, $v)
        If @error = 0 Then
          ; Valid value - test it's name
            If StringInStr($val, $searchval) Then
                $found = $found & $startkey & "\" & $val & @LF
            EndIf
          ; test it's data
            $readval = RegRead($startkey, $val)
            If StringInStr($readval, $searchval) Then
                $found = $found & $startkey & "\" & $val & " = " & $readval & @LF
            EndIf
            $v += 1
        Else
          ; No more values here
            ExitLoop
        EndIf
    WEnd
    
  ; This loop checks subkeys
    $k = 1
    While 1
        $key = RegEnumKey($startkey, $k)
        If @error = 0 Then
          ; Valid key - test it's name
            If StringInStr($key, $searchval) Then
                $found = $found & $startkey & "\" & $key & "\" & @LF
            EndIf
          ; Now search it
            $found = $found & _RegSearch($startkey & "\" & $key, $searchval)
        Else
          ; No more keys here
            ExitLoop
        EndIf
        $k += 1
    WEnd
    
  ; Return results
    Return $found
EndFunc ;==>_RegSearch
Edited by frankpintosr

Share this post


Link to post
Share on other sites
rasim

Example:

#include <Date.au3>

Global $aType[8] = [7, "REG_SZ", "REG_EXPAND_SZ", "REG_BINARY", "REG_DWORD", 0, 0, "REG_MULTI_SZ"]

Dim $RegKey = "HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt"
Dim $FileHandle = FileOpen("c:\RegList.txt", 1)
Dim $count = 0

FileWrite($FileHandle, "KeyName: " & $RegKey & " - " & _Now() & @CRLF & @CRLF)

While 1
    $count += 1
    $enum = RegEnumVal($RegKey, $count)
    If @error Then ExitLoop
    $read = RegRead($RegKey, $enum)
    
    FileWrite($FileHandle, "Value " & $count & @CRLF & _
              "Name: " & $enum & @CRLF & _
              "Type: " & $aType[@extended] & @CRLF & _
              "Data: " & $read & @CRLF & @CRLF)
WEnd

FileClose($FileHandle)
:)

Share this post


Link to post
Share on other sites
frankpintosr

Thank you i will give it a shot. So just to be clear, the scrip you provided only does the part of listing the vaules under the keys previuosly located right? So I still need the other script to look for the keys and then add your script to get all the values, right?

Thanks for your help!!

Frank

Example:

#include <Date.au3>

Global $aType[8] = [7, "REG_SZ", "REG_EXPAND_SZ", "REG_BINARY", "REG_DWORD", 0, 0, "REG_MULTI_SZ"]

Dim $RegKey = "HKEY_LOCAL_MACHINE\SOFTWARE\AutoIt v3\AutoIt"
Dim $FileHandle = FileOpen("c:\RegList.txt", 1)
Dim $count = 0

FileWrite($FileHandle, "KeyName: " & $RegKey & " - " & _Now() & @CRLF & @CRLF)

While 1
    $count += 1
    $enum = RegEnumVal($RegKey, $count)
    If @error Then ExitLoop
    $read = RegRead($RegKey, $enum)
    
    FileWrite($FileHandle, "Value " & $count & @CRLF & _
              "Name: " & $enum & @CRLF & _
              "Type: " & $aType[@extended] & @CRLF & _
              "Data: " & $read & @CRLF & @CRLF)
WEnd

FileClose($FileHandle)
:)

Share this post


Link to post
Share on other sites
frankpintosr

I tired it and it works great for the exact key you specify. But I need it to include that key and all sub keys and all values under each key. I am including a screen shot of the registry. If I select the ODBC key, I should get everything underneath. I tried to odify the code but could not get anywhere. So eveything listed below is what I am trying to export, all of those sub keys and values too. Thanks so much for your help so far, we are close......

Key Name: HKEY_CURRENT_USER\Software\ODBC\ODBC.INI

Class Name: <NO CLASS>

Last Write Time: 5/1/2008 - 12:07 PM

Key Name: HKEY_CURRENT_USER\Software\ODBC\ODBC.INI\dBASE Files

Class Name: <NO CLASS>

Last Write Time: 4/21/2008 - 11:01 PM

Value 0

Name: Driver

Type: REG_SZ

Data: C:\WINDOWS\System32\odbcjt32.dll

Value 1

Name: DriverId

Type: REG_DWORD

Data: 0x215

Value 2

Name: SafeTransactions

Type: REG_DWORD

Data: 0x0

Value 3

Name: UID

Type: REG_SZ

Data:

Key Name: HKEY_CURRENT_USER\Software\ODBC\ODBC.INI\dBASE Files\Engines

Class Name: <NO CLASS>

Last Write Time: 4/21/2008 - 11:01 PM

Key Name: HKEY_CURRENT_USER\Software\ODBC\ODBC.INI\dBASE Files\Engines\Xbase

Class Name: <NO CLASS>

Last Write Time: 4/21/2008 - 11:01 PM

Value 0

Name: ImplicitCommitSync

Type: REG_SZ

Data:

Value 1

Name: Threads

Type: REG_DWORD

Data: 0x3

Value 2

Name: UserCommitSync

Type: REG_SZ

Data: Yes

Key Name: HKEY_CURRENT_USER\Software\ODBC\ODBC.INI\Excel Files

Class Name: <NO CLASS>

Last Write Time: 4/21/2008 - 11:01 PM

Value 0

Name: Driver

Type: REG_SZ

Data: C:\WINDOWS\System32\odbcjt32.dll

Value 1

Name: DriverId

Type: REG_DWORD

Data: 0x316

Value 2

Name: SafeTransactions

Type: REG_DWORD

Data: 0x0

Value 3

Name: UID

Type: REG_SZ

Data:

Key Name: HKEY_CURRENT_USER\Software\ODBC\ODBC.INI\Excel Files\Engines

Class Name: <NO CLASS>

Last Write Time: 4/21/2008 - 11:01 PM

Key Name: HKEY_CURRENT_USER\Software\ODBC\ODBC.INI\Excel Files\Engines\Excel

Class Name: <NO CLASS>

Last Write Time: 4/21/2008 - 11:01 PM

Value 0

Name: ImplicitCommitSync

Type: REG_SZ

Data:

Value 1

Name: Threads

Type: REG_DWORD

Data: 0x3

Value 2

Name: UserCommitSync

Type: REG_SZ

Data: Yes

Value 3

Name: FirstRowHasNames

Type: REG_BINARY

Data:

00000000 01 .

Key Name: HKEY_CURRENT_USER\Software\ODBC\ODBC.INI\Frank User DSN

Class Name: <NO CLASS>

Last Write Time: 5/1/2008 - 12:07 PM

Value 0

Name: Driver

Type: REG_SZ

Data: C:\WINDOWS\System32\odbcjt32.dll

Value 1

Name: DBQ

Type: REG_SZ

Data: C:\Documents and Settings\xp-fpinto1\My Documents\doc1.mdb

Value 2

Name: Description

Type: REG_SZ

Data: Frank User DSN

Value 3

Name: DriverId

Type: REG_DWORD

Data: 0x19

Value 4

Name: FIL

Type: REG_SZ

Data: MS Access;

Value 5

Name: PWD

Type: REG_SZ

Data: password

Value 6

Name: SafeTransactions

Type: REG_DWORD

Data: 0x0

Value 7

Name: UID

Type: REG_SZ

Data: frank

Key Name: HKEY_CURRENT_USER\Software\ODBC\ODBC.INI\Frank User DSN\Engines

Class Name: <NO CLASS>

Last Write Time: 5/1/2008 - 12:07 PM

Key Name: HKEY_CURRENT_USER\Software\ODBC\ODBC.INI\Frank User DSN\Engines\Jet

Class Name: <NO CLASS>

Last Write Time: 5/1/2008 - 12:07 PM

Value 0

Name: ImplicitCommitSync

Type: REG_SZ

Data:

Value 1

Name: MaxBufferSize

Type: REG_DWORD

Data: 0x800

Value 2

Name: PageTimeout

Type: REG_DWORD

Data: 0x5

Value 3

Name: Threads

Type: REG_DWORD

Data: 0x3

Value 4

Name: UserCommitSync

Type: REG_SZ

Data: Yes

Key Name: HKEY_CURRENT_USER\Software\ODBC\ODBC.INI\MS Access Database

Class Name: <NO CLASS>

Last Write Time: 4/21/2008 - 11:01 PM

Value 0

Name: Driver

Type: REG_SZ

Data: C:\WINDOWS\System32\odbcjt32.dll

Value 1

Name: DriverId

Type: REG_DWORD

Data: 0x19

Value 2

Name: SafeTransactions

Type: REG_DWORD

Data: 0x0

Value 3

Name: UID

Type: REG_SZ

Data:

Key Name: HKEY_CURRENT_USER\Software\ODBC\ODBC.INI\MS Access Database\Engines

Class Name: <NO CLASS>

Last Write Time: 4/21/2008 - 11:01 PM

Key Name: HKEY_CURRENT_USER\Software\ODBC\ODBC.INI\MS Access Database\Engines\Jet

Class Name: <NO CLASS>

Last Write Time: 4/21/2008 - 11:01 PM

Value 0

Name: ImplicitCommitSync

Type: REG_SZ

Data:

Value 1

Name: Threads

Type: REG_DWORD

Data: 0x3

Value 2

Name: UserCommitSync

Type: REG_SZ

Data: Yes

Key Name: HKEY_CURRENT_USER\Software\ODBC\ODBC.INI\ODBC Data Sources

Class Name: <NO CLASS>

Last Write Time: 5/1/2008 - 12:07 PM

Value 0

Name: MS Access Database

Type: REG_SZ

Data: Microsoft Access Driver (*.mdb)

Value 1

Name: Excel Files

Type: REG_SZ

Data: Microsoft Excel Driver (*.xls)

Value 2

Name: dBASE Files

Type: REG_SZ

Data: Microsoft dBase Driver (*.dbf)

Value 3

Name: Frank User DSN

Type: REG_SZ

Data: Microsoft Access Driver (*.mdb)

Thank you i will give it a shot. So just to be clear, the scrip you provided only does the part of listing the vaules under the keys previuosly located right? So I still need the other script to look for the keys and then add your script to get all the values, right?

Thanks for your help!!

Frank

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×