Jump to content

Recommended Posts

I started making this script after I read this topic.

But I don't know how to create an infinite loop that searches recursively.

I get confused and my brain hurts when I'm trying to find a solution.

Can someone please help.

Here's the script: http://www.autoitscript.com/fileman/users/public/SlimShady/SearchReg.au3

Thank you.

Link to post
Share on other sites

I couldnt get autoit to search through the registry... so i exported to a text file and searched through that instead.

When i say search, i *literally* mean search. It opens it in wordpad, selects the line, copies to notepad, and checks the variables.

If this is the solution you want i can drop the code to you no probs.

Sitting comfortably behind the code.

Link to post
Share on other sites

No, I mean searching through the registry on-the-fly.

First I was stupid and exported HKEY_LOCAL... and HKEY_CURRENT...

The files were huge and it took hours :ph34r: to search through the 2 files.

That's why I'm using RegEnumKey and RegEnumVal (available in beta version).

I'll check my script again and see if I can figure it out now.

Link to post
Share on other sites

@SlimShady: I will try it.

I have a loop for quering directories (permission-difference-checker) so I try to reconfigure it for registry...

Maybe another one has a solution...

Edit: forgot something: what should be the result?

An array with the found keys, data, etc. or like in regedit the first/next entry?

Edited by Holger
Link to post
Share on other sites

@SlimShady: try this:

Global $regarr[1000][3]; -> maybe put bigger with "redim" in the RegToArr-function
;means [what][subkey][foundin] -> ["key"][subkey][...] or ["value"][subkey][...] or ["valuevalue"][subkey][...]
Global $arridx = 0

$searchstring = "SourcePath"
RegSearch("HKEY_LOCAL_MACHINE")
;RegSearch("HKEY_USERS")

For $idx = 1 To $regarr[0][0]
    Msgbox(0,"",$regarr[$idx][0] & @LF & $regarr[$idx][1] & @LF & $regarr[$idx][2])
Next

$regarr = 0

Exit

Func RegSearch($subreg)
    Local $subreg, $idx, $subidx, $regkey, $regkeyname, $regkeyvalue, $regvalue
    $idx = 1
    While 1
  $regkey = RegEnumKey($subreg,$idx)
  If @error = -1 Or @error = 1 Then ExitLoop
  If StringInStr($regkey,$searchstring) > 0 Then RegToArr("key",$subreg,$regkey)
  $regkeyname = $subreg & "\" & $regkey
  $subidx = 1
  While 1
    $regkeyvalue = RegEnumVal($regkeyname,$subidx)
    If @error = -1 Or @error = 1 Then ExitLoop
    If StringInStr($regkeyvalue,$searchstring) > 0 Then RegToArr("value",$regkeyname,$regkeyvalue)
    $regvalue = RegRead($regkeyname,$regkeyvalue)
  ;If $regvalue <> 1 And StringInStr($regvalue,$searchstring) > 0 Then RegToArr("valuevalue",$regkeyname,$regvalue)
    If $regvalue <> 1 And StringInStr($regvalue,$searchstring) > 0 Then RegToArr("valuevalue",$regkeyname & "\" & $regkeyvalue,$regvalue)

    $subidx = $subidx + 1
  WEnd
  RegSearch($regkeyname)
  $idx = $idx + 1
;Sleep(1); better set to reduce cpu like Regedit does
    WEnd
EndFunc

Func RegToArr($string,$key,$value)
    $arridx = $arridx + 1
    If $arridx = (UBound($regarr) - 1) Then Redim $regarr[$arridx + 26][3]; 25 more array-fields
    $regarr[0][0] = $arridx
    $regarr[$arridx][0] = $string
    $regarr[$arridx][1] = $key
    $regarr[$arridx][2] = $value
EndFunc

I hope it works so far.

But you could test it out and give short feedback if this is what you need...

Edit: ok, there is a little but: so maybe it is better to write the $regkeyvalue also to the array...

Edited by Holger
Link to post
Share on other sites

I changed ;Sleep(1) to Sleep(5) and ran the script.

After a while I got this error and AutoIt closed the script.

---------------------------

AutoIt Error

---------------------------

Line 43  (File "C:\Documents and Settings\_my_username_\Desktop\RegSearch.au3"):

$regarr[$arridx][0] = $string

^ ERROR

Error: Array variable has incorrect number of subscripts or subscript dimension range exceeded.

---------------------------

OK

---------------------------

Link to post
Share on other sites

You have to modify the RegToArr() a little bit cause of more values then the array can save:

Func RegToArr($string,$key,$value)
    $arridx = $arridx + 1
    If $arridx = (UBound($regarr) - 1) Then Redim $regarr[$arridx + 26][3]; 25 more array-fields
    $regarr[0][0] = $arridx
    $regarr[$arridx][0] = $string
    $regarr[$arridx][1] = $key
    $regarr[$arridx][2] = $value
EndFunc

So with UBound(array-size)-checking that should no problem anymore :ph34r:

Edited by Holger
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...