0

Using VBA, I need to find all specified string occurences in windows registry (search in Key names, Value names and Value data - somewhat as we do in Find dialog in Windows Regedit app) and when found then replace it by other specified string.

Parameters of the replace sub

  1. should be similar to the ones in Find dialog in standard Windows Regedit app

and additionally are needed:

  1. the "StartingKeyName" parameter to limit the search to look only in a specified registry branch (if StartingKeyName = "Computer" the search in whole registry, if StartingKeyName = "Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control" then search only in "Computer\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control" branch

  2. a binary switch parameter, e.g. "SearchInSubkeys" specifying using "1" and "0" whether the sub should or should not search in subkeys of the specified StartingKeyName.

Any ideas pls?

pseudocode would be:

sub FindAndReplace(FindWhat:string; LookAt:string; StartingKeyName:string; SearchInSubkeys:binary;ReplaceTo:string)
 // FindWhat - string to find (as in Windows regedit Find dialog)
 // LookAt - "K" for Key names, "V" for Value names, "D" for Value data, can be a combination of these characters, i.e. if LookAt = "KD" then search only in Key names and Value data
 // StartingKeyName: limit the search to specified key
 // SearchInSubkeys: binary switch to specify whether to only search in specified StartingKeyName name, its Value names, and those Values' data, or to recursively search in the subkeys of the specified StartingKeyName (similar to "search in subfolders" in windows explorer).
 // ReplaceTo - replacing string

 loop in the StartingKey branch, taking the SearchInSubfolders parameter into the account

 search in Key names / Value names / Value data according to the LookAt parameter

 if FindWhat string found
 then replace it by ReplaceTo string

 endloop;

endsub;

but please do not be limited to only this structure at all, it is only a quick example

J. Doe
  • 85
  • 8
  • http://www.cpearson.com/excel/registry.htm – Tim Williams Aug 27 '19 at 16:11
  • FYI HKLM will require admin privs to modify. – Mathieu Guindon Aug 27 '19 at 16:33
  • @Tim Williams thanks a lot for a great tip, I've found it some time ago. I could not find out which function at Pearson should I use to do the Find part of our FindAndReplace sub. I do not know how to search thorugh all registry Key names, Value names and Value data. How to loop through all the registry Key names, Value names and Value data to do the "if match then replace". – J. Doe Aug 27 '19 at 20:57
  • I don't think VBA gives you any way to do that. – Tim Williams Aug 27 '19 at 21:50
  • @TimWilliams Tim check this, I would elaborate on it in some sparetime: enumerate using WMI and StdRegProv and then loop; see https://learn.microsoft.com/en-us/windows/win32/wmisdk/obtaining-registry-data AND https://stackoverflow.com/questions/39464344/read-registry-keys-from-within-vba-using-windows-shell (the later is not finalized) – J. Doe Aug 27 '19 at 22:14
  • @TimWilliams Pearson has some enumeration as well in his code, should check it too – J. Doe Aug 27 '19 at 22:19

0 Answers0