Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Loop Through Registry Key

914 views
Skip to first unread message

Marty Henderson

unread,
Apr 13, 1999, 3:00:00 AM4/13/99
to
This may be elementry so please humor me.

I'm trying to "For Each/Next" loop through a registry key - reading all
values under the key - without sucess. I want to enum the contents of a key
into an array, or just operate on the key's contents on the fly.

I'm trying something like this...

Set WSHShell = WScript.CreateObject("WScript.Shell")
BaseKey = "HKLM\SOFTWARE\ABC Co\Application\Stuff"
For Each RegThing in WshShell.RegRead(BaseKey)
WScript.Echo RegThing
Next

This code compiles but jumps into the debugger at the For Each line. Am I
going about this wrong? What's the best way to enum all entries under a
given key?

Thanks in advance,

Marty Henderson
pcHouseCall

Marty Henderson

unread,
Apr 13, 1999, 3:00:00 AM4/13/99
to
Please not that since this is a registry KEY I also tried...

BaseKey = "HKLM\SOFTWARE\ABC Co\Application\Stuff\"


Marty Henderson <mOOs...@pchcall.com> wrote in message
news:#t9r5#fh#GA.260@cppssbbsa03...

Michael Harris

unread,
Apr 13, 1999, 3:00:00 AM4/13/99
to
Shell.RegRead returns the value of the key, not an object that represents the key.  If that's what you need, then use RegObj.dll.

--
Mike Harris
Marty Henderson <mOOs...@pchcall.com> wrote in message news:OI8HJJgh#GA.263@cppssbbsa03...

Marty Henderson

unread,
Apr 14, 1999, 3:00:00 AM4/14/99
to
Thanks for the response, Michael. Um, forgive my ignorance but, how does one use RegObj.dll? Where are it's VBscript/WSH implementations documented? Or must one use VB or C++?
 
The bottom line of the question is this: Is there ANY way to enum the contents of a registry key in WSH/VBscript?
 
Thanks,
 
Marty Henderson
Michael Harris <mik...@ibm.net> wrote in message news:Oac2Imih#GA.266@cppssbbsa03...

Michael Harris

unread,
Apr 14, 1999, 3:00:00 AM4/14/99
to

RegObj.dll let's you access local and remote registries via an object model that includes collections that let you enumerate subkeys and/or values of a given key.

You can download RegObj.dll from

<http://msdn.microsoft.com/vbasic/downloads/download.asp?ID=026>

If you haven't registered with MS with a vbasic or vstudio product id, you may not be able to go straight to this page. If so, try starting at
<http://msdn.microsoft.com/vstudio> and follow the Registration link in the TOC on the left... Registering doesn't cost you anything other a little loss of privacy <g>!

--
Mike Harris
 
 
Marty Henderson <mOOs...@pchcall.com> wrote in message news:OyCoGVoh#GA.259@cppssbbsa03...

Marty Henderson

unread,
Apr 14, 1999, 3:00:00 AM4/14/99
to
OK, thanks Michael. I went to the site and got the stuff. I think I can do
this from their VB sample code. But if anyone has implimented these
automation objects in VBscript it would be nice to see that code example
here.

Thanks,

Marty Henderson
Michael Harris <mik...@safeco.com> wrote in message
news:#VdXD7oh#GA....@cppssbbsa02.microsoft.com...

Michael Harris

unread,
Apr 16, 1999, 3:00:00 AM4/16/99
to
RegObj.dll doesn't require a license...

--
Mike Harris
Gunnar Olerud <gun...@merxmollis.nl> wrote in message news:Ok$HXtFi#GA.269@cppssbbsa03...
Actually, your first example works with some minor modifications. You have
to start the string with a "\" and you have to use the long names of the top
level keys.

    BaseKey  = "\HKEY_LOCAL_MACHINE\SOFTWARE\ABC Co\Application\Stuff"

In this case when you use it as a collection it doesn't matter if you have
the ending "\" or not.
Apparently there must be some hidden (undocumented) features of the
WshShell.RegRead operation.

Although the RegObj.dll is very good you have to download and install (+
having the license). I think if you only do some simple operations in the
local registry I prefer the WshShell.RegXXX operations due to the
installation and the license issues.

Gunnar Olerud
gun...@merxmollis.nl



Gunnar Olerud

unread,
Apr 17, 1999, 3:00:00 AM4/17/99
to

Gunnar Olerud

unread,
Apr 17, 1999, 3:00:00 AM4/17/99
to
Sorry, I became a bit confused with the RegObj.dll. My statement in the
previous message is not true. You can't use the WshShell.RegRead to loop
through the registry.

Gunnar

Gunnar Olerud wrote in message ...

Marty Henderson

unread,
Apr 19, 1999, 3:00:00 AM4/19/99
to
OK, thanks to Michael's help I have achieved my goal. For the benefit of
those reading this thread I'm posting an example of looping through keys and
values under a given key using RegObj.dll. Here is the example...

Dim oReg, oRegKey, oRegKey1, strKeyName, MyValue, MyKey

Set oReg = CreateObject("RegObj.Registry")
strKeyName = "\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows"
Set oRegKey = oReg.RegKeyFromString(strKeyName)
For Each MyKey in oRegKey.SubKeys
Set oRegKey1 = oReg.RegKeyFromString(strKeyName & "\" & MyKey)
For Each MyValue in oRegKey1.Values
WScript.Echo "Value in Key " & MyKey & ": " & MyValue
Next
Next

So, you CAN get there from here! You just have to register an ActiveX DLL
first. Cool!

Marty Henderson
pcHouseCall
http://www.pchcall.com/

Michael Harris <mik...@ibm.net> wrote in message

news:eWMvgGIi#GA....@cppssbbsa02.microsoft.com...


RegObj.dll doesn't require a license...

--
Mike Harris

Gunnar Olerud <gun...@merxmollis.nl> wrote in message
news:Ok$HXtFi#GA.269@cppssbbsa03...

Marty Henderson

unread,
Apr 19, 1999, 3:00:00 AM4/19/99
to

Gunnar Olerud

unread,
Apr 19, 1999, 3:00:00 AM4/19/99
to
The example below shows a recursive parsing sub-function.

Dim objReg, objKey
Set objReg = Wscript.CreateObject("RegObj.Registry")

Set objKey = objReg.RegKeyFromString("\HKEY_CURRENT_USER\Control Panel")
parseKey objKey.SubKeys

Wscript.Quit


'
****************************************************************************
****
' *
' * parseKey - parses through and displays the full name of each sub-key
' * in a collection of keys
' *
' * @param objCollection a collection of keys
' *
Sub parseKey(objCollection)
Dim item
For Each item in objCollection
parseKey item.SubKeys
MsgBox item.FullName
Next
End Sub

Gunnar Olerud
gun...@merxmollis.nl


Marty Henderson wrote in message ...

Tom Lavedas

unread,
Apr 26, 1999, 3:00:00 AM4/26/99
to
Gunnar Olerud wrote:
>
> Sorry, I became a bit confused with the RegObj.dll. My statement in the
> previous message is not true. You can't use the WshShell.RegRead to loop
> through the registry.
>
> Gunnar
>
> Gunnar Olerud wrote in message ...
> >Actually, your first example works with some minor modifications. You have
> >to start the string with a "\" and you have to use the long names of the
> top
> >level keys.
> >
> > BaseKey = "\HKEY_LOCAL_MACHINE\SOFTWARE\ABC Co\Application\Stuff"
> >
> >In this case when you use it as a collection it doesn't matter if you have
> >the ending "\" or not.
> >Apparently there must be some hidden (undocumented) features of the
> >WshShell.RegRead operation.
> >
> >Although the RegObj.dll is very good you have to download and install (+
> >having the license). I think if you only do some simple operations in the
> >local registry I prefer the WshShell.RegXXX operations due to the
> >installation and the license issues.
> >
> >Gunnar Olerud
> >gun...@merxmollis.nl

For the reasons you mention (not needing other downloads), I have put
together this approach that DOES recurse through a registry key.

' RegRecurse.vbs - A example of using Regedit.exe to recurse
' a registry key.
' Tom Lavedas <lav...@pressroom.com>
'

Set WSHShell = WScript.CreateObject("WScript.Shell")

Set objFS = WScript.CreateObject ("Scripting.FileSystemObject")
' For example, part of a search for an installed CD-ROM
strName = "HKEY_LOCAL_MACHINE\Enum\SCSI"
TempName = WshShell.Environment("PROCESS").Item("TEMP")
TempName = TempName & "\~" & objFS.GetTempName
Result = WSHShell.Run ("regedit /e " & TempName & " " & strName, _
1, True)
if Result > 0 Then WScript.Quit(1)
Set objF = objFS.OpenTextFile(TempName)
Do
Line = objF.ReadLine
if Instr(Line, Chr(91)) > 0 Then ' Chr(91) = "["
Line = Mid(Line, 2, Len(Line) - 2)
Result = WSHShell.Popup (Line, 0, "Registry Item", 1)
if Result = vbCancel Then Exit Do
End if
Loop Until objF.AtEndOfStream
objF.Close
objFS.DeleteFile TempName, True

I hope it doesn't bother anyone's sensibilities because of the use of
Regedit. Regedit's not an object library like RegRead, but I figure
it's always installed along with Windows, making it safe enough to use.

Tom Lavedas
-----------
http://www.pressroom.com/~tglbatch/

0 new messages