Hi!

I Need to find a Key (folder) of the registery holding a String which
contains a substring.

For example : under HKEY_LOCAL_MACHINE\SOFTWARE\MyCompany\MySW there is
a Keys named VER_A and VER_B.
VER_B has a string named "Description" The value of "Description" is
"Better".

I want to go over all Keys in Under
HKEY_LOCAL_MACHINE\SOFTWARE\MyCompany\MySW, in each key I want to Look
for a string named "description" and then if I found such a string see
if it contains a substring named "better" (I do not care for capital
letters). At the end of the process I need to get the key name (folder
name).
In this example my aim is to get the string "VER_B".

Sorry if the description is complicated :-))

Thanks
Maurice

Re: Newby question : How do I Search registery folder for a string by Torgeir

Torgeir
Sun May 29 14:54:35 CDT 2005

zmau@UltimateEmail.com wrote:

> Hi!
>
> I Need to find a Key (folder) of the registery holding a String which
> contains a substring.
>
> For example : under HKEY_LOCAL_MACHINE\SOFTWARE\MyCompany\MySW there is
> a Keys named VER_A and VER_B.
> VER_B has a string named "Description" The value of "Description" is
> "Better".
>
> I want to go over all Keys in Under
> HKEY_LOCAL_MACHINE\SOFTWARE\MyCompany\MySW, in each key I want to Look
> for a string named "description" and then if I found such a string see
> if it contains a substring named "better" (I do not care for capital
> letters). At the end of the process I need to get the key name (folder
> name).
> In this example my aim is to get the string "VER_B".
Hi,

This works for me:

'--------------------8<----------------------

' Constants for the StdRegProv WMI class
Const HKLM = &H80000002

' note the trailing backslash
sRegBase = "SOFTWARE\MyCompany\MySW\"

sComputer = "." ' use "." for local computer
Set oReg = _
GetObject("winmgmts:{impersonationLevel=impersonate}!\\" _
& sComputer & "/root/default:StdRegProv")

iRC = oReg.EnumKey(HKLM, sRegBase, arSubKeys)

sKeyName = "" ' init value

If iRC = 0 And IsArray(arSubKeys) Then ' registry key exists
For Each sKey In arSubKeys
oReg.GetStringValue HKLM, sRegBase & sKey, "Description", sValueData
If InStr(1, sValueData, "Better", vbTextCompare) > 0 Then
sKeyName = sKey
' key found, abort the key enumeration
Exit For
End If
Next
End If

If sKeyName <> "" Then
WScript.Echo "Correct value found under the registry key " & sKeyName
Else
WScript.Echo "No registry key found"
End If

'--------------------8<----------------------


--
torgeir, Microsoft MVP Scripting and WMI, Porsgrunn Norway
Administration scripting examples and an ONLINE version of
the 1328 page Scripting Guide:
http://www.microsoft.com/technet/scriptcenter/default.mspx