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
BaseKey = "HKLM\SOFTWARE\ABC Co\Application\Stuff\"
Marty Henderson <mOOs...@pchcall.com> wrote in message
news:#t9r5#fh#GA.260@cppssbbsa03...
Marty Henderson <mOOs...@pchcall.com> wrote in message news:OI8HJJgh#GA.263@cppssbbsa03...
Michael Harris <mik...@ibm.net> wrote in message news:Oac2Imih#GA.266@cppssbbsa03...
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
Marty Henderson <mOOs...@pchcall.com> wrote in message news:OyCoGVoh#GA.259@cppssbbsa03...
Thanks,
Marty Henderson
Michael Harris <mik...@safeco.com> wrote in message
news:#VdXD7oh#GA....@cppssbbsa02.microsoft.com...
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
Gunnar Olerud wrote in message ...
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...
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 ...
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/