How to read registry key containing many string values 
Author Message
 How to read registry key containing many string values

Ok,

vb newbie needs some help ...

I know how to read the registry for a specific, single
string value; eg,

set WshShell = CreateObject("WScript.Shell")
Brand = WshShell.RegRead ("HKLM\Software\ABC\XYZ\Brand")

Assume that a registry key had 1 to "n" string values,
each with a different name, within the key; eg,

HKLM\Software\ABC\XYZ\StringValues
- String1 123
- String2 456
- String3 789
- Stringn 000

I do not know the specific string value name within
HKLM\Software\ABC\XYZ\StringValues and do not need to
know.  But I need to read each string value (String1,
String2 etc) and process each value (123, 456 etc).  How
would I accomplish reading the key and its string values
and processing each individually?



Mon, 27 Dec 2004 03:12:19 GMT  
 How to read registry key containing many string values

Quote:

> Assume that a registry key had 1 to "n" string values,
> each with a different name, within the key; eg,

> HKLM\Software\ABC\XYZ\StringValues
> - String1 123
> - String2 456
> - String3 789
> - Stringn 000

> I do not know the specific string value name within
> HKLM\Software\ABC\XYZ\StringValues and do not need to
> know.  But I need to read each string value (String1,
> String2 etc) and process each value (123, 456 etc).  How
> would I accomplish reading the key and its string values
> and processing each individually?

That is easy with WMI:

' ----- Code start -----
Const HKLM = &H80000002
sKeyPath = "Software\Microsoft\Windows\CurrentVersion"

Set oReg =GetObject("Winmgmts:root\default:StdRegProv")
If oReg.EnumValues(HKLM, sKeyPath, aValueNames, aValueTypes) = 0 Then

  For i = 0 To UBound(aValueNames)
    ' Check for type "REG_SZ" (= 1)
    If aValueTypes(i) = 1 Then
      If oReg.GetStringValue(HKLM, sKeyPath, aValueNames(i), sValue) = 0 Then
        WScript.Echo "Value name: " & aValueNames(i)
        WScript.Echo "Value data: " & sValue
        WScript.Echo
      End If
    End If
  Next
Else
  WScript.Echo "Key does not exist!"
End If
' ----- Code stop -----

WMI comes default with WinMe/Win2k/WinXP, can be installed on Win9x/WinNT.

WMI Class StdRegProv:
http://msdn.microsoft.com/library/en-us/wmisdk/wmi/stdregprov.asp

If you don't have WMI, you can from a script use regedit /e to export the key in
question to a file, and parse the file. For examples on the regedit method, take
a look at this newsgroup article:


Subject: Re: How many values in my registry subkey ?
Date: Wed, 10 Jul 2002 11:43:39 -0500
From: <Alex K. Angelopoulos (MVP)>
Newsgroups: microsoft.public.scripting.wsh

At the moment I write this, it is not archived at Google yet, but it can be

hours.
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&th=6cac6c050c25b1ad

--
torgeir



Mon, 27 Dec 2004 04:58:20 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Read all string values from registry key

2. Reading registry values containing a backslash (\)

3. creating keys and string values in registry

4. reading registry key values

5. Read a value of a key in the Registry

6. Help! cannot read Default value from Registry Keys

7. Problem reading REG_EXPAND_SZ type Key Values from registry

8. Help! cannot read Default value from Registry Keys

9. api to read registry key values

10. Read Registry Keys and Trees / API Call for Registry access

11. REGISTRY How can I read a registry key?

12. problem with sql server string values containing special chars

 

 
Powered by phpBB® Forum Software