read (all) subkeys of a given registry key ? 
Author Message
 read (all) subkeys of a given registry key ?

Can anyone tell me
how to read (all) the subkeys of a given registry key using VBScript
(not Visual Basic or C), if the names of this subkeys are NOT known
before ?

1. example:

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\
***UNKNOWN***\DisplayName
^^^^^^^^^^^^^

How can I get the subkeys of  

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\

in order to read a subkey (DisplayName) of this subkeys ?

2. example:
HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Class\Net\000***UNKNOWN_NUMBER\DeviceDesc

Reading a KNOWN registry key:
----------------------------

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

'If strName ends with the backslash character (\), this method returns
the key instead of the value.

' Read from value "Val".
WScript.Echo WshShell.RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\")

' Read from key "Key".
WScript.Echo WshShell.RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\VB5\DisplayName")
WScript.Echo WshShell.RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\Office8.0\DisplayName")

But normally I don't know the name of "VB5" and "Office8.0".

Any VBScript expert who can help me ?

Norbert Render



Fri, 19 Mar 2004 02:35:37 GMT  
 read (all) subkeys of a given registry key ?
Pure WSH can not enumerate registry keys.

Several choises as a workaround (from WSH):

A)
Shell.run regedit to export to a .reg and parse the .reg file.

REGEDIT /E filename3 [regpath1]
REGEDIT  /E:A filename3 [regpath1]
REGEDIT  /A filename3 [regpath1]

  /E filename3    Specifies the file to export the registry to.
  /E:A and /A     Specifies ASCII output for W2k/WXP (default Unicode)
  regpath1          Specifies the starting registry key to export from.
                         (Defaults to exporting the entire registry).

B)
Install RegObj.dll that represents the registry via an object model with methods to enumerate keys/values (and a lot more).
RegObj.dll is a free, unsupported dll from MS.

You can get RegObj.dll from:
Win32 Scripting [Clarence Washington]
http://cwashington.netreach.net/main_site/downloads

You can use a wrapper (encapsulate_regobj.zip) from http://cwashington.netreach.net  to get it more "user friendly".
You can also find a couple of sample scripts which demonstrate how to enumerate there.

C)
Use WMI's StdRegProv (Standard Registry Provider). WMI comes default with W2k/WXP, can be installed on W9x/WNT.

EnumKey Method in Class StdRegProv
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmis...

D)
Use a 3. party component for it:
Eg. http://www.jsware.net/jsware/scripts.html (JSSys.DLL)

Regards,
Torgeir

Quote:

> Can anyone tell me
> how to read (all) the subkeys of a given registry key using VBScript
> (not Visual Basic or C), if the names of this subkeys are NOT known
> before ?

> 1. example:

> HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\
> ***UNKNOWN***\DisplayName
> ^^^^^^^^^^^^^

> How can I get the subkeys of

> HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\

> in order to read a subkey (DisplayName) of this subkeys ?

> 2. example:
> HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Class\Net\000***UNKNOWN_NUMBER\DeviceDesc

> Reading a KNOWN registry key:
> ----------------------------

> Set WshShell = WScript.CreateObject("WScript.Shell")

> 'If strName ends with the backslash character (\), this method returns
> the key instead of the value.

> ' Read from value "Val".
> WScript.Echo WshShell.RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\")

> ' Read from key "Key".
> WScript.Echo WshShell.RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\VB5\DisplayName")
> WScript.Echo WshShell.RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\Office8.0\DisplayName")

> But normally I don't know the name of "VB5" and "Office8.0".

> Any VBScript expert who can help me ?

> Norbert Render



Fri, 19 Mar 2004 03:09:04 GMT  
 read (all) subkeys of a given registry key ?
See http://www.pstruh.cz/help/regedit/cl75.htm

--
Antonin Foller
PSTRUH Software
http://www.pstruh.cz

Quote:
> Can anyone tell me
> how to read (all) the subkeys of a given registry key using VBScript
> (not Visual Basic or C), if the names of this subkeys are NOT known
> before ?

> 1. example:

> HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\
> ***UNKNOWN***\DisplayName
> ^^^^^^^^^^^^^

> How can I get the subkeys of

> HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall\

> in order to read a subkey (DisplayName) of this subkeys ?

> 2. example:

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\Class\Net\000***UNKNOWN
_NUMBER\DeviceDesc
Quote:

> Reading a KNOWN registry key:
> ----------------------------

> Set WshShell = WScript.CreateObject("WScript.Shell")

> 'If strName ends with the backslash character (\), this method returns
> the key instead of the value.

> ' Read from value "Val".
> WScript.Echo

WshShell.RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersi
on\Uninstall\")
Quote:

> ' Read from key "Key".
> WScript.Echo

WshShell.RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersi
on\Uninstall\VB5\DisplayName")
Quote:
> WScript.Echo

WshShell.RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersi
on\Uninstall\Office8.0\DisplayName")

- Show quoted text -

Quote:

> But normally I don't know the name of "VB5" and "Office8.0".

> Any VBScript expert who can help me ?

> Norbert Render



Sat, 20 Mar 2004 06:10:14 GMT  
 read (all) subkeys of a given registry key ?
'WMI Rox
'Substitute RegHive and RegKey for your target key.
'Credit to http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wmis...

On Error Resume Next
Option Explicit

Const HKEY_CURRENT_USER = &H80000001
Const HKEY_CLASSES_ROOT = 0x80000000
Const HKEY_CURRENT_USER = 0x80000001
Const HKEY_LOCAL_MACHINE = 0x80000002
Const HKEY_USERS = 0x80000003
Const HKEY_CURRENT_CONFIG = 0x80000005
Const HKEY_DYN_DATA = 0x80000006

Dim RegHive
Dim RegKey
RegHive = HKEY_CURRENT_USER 'Select registry hive constant from above list.
RegKey = "Software\Microsoft\Windows\CurrentVersion\Policies" 'Path to key to delete (no leading/trailing slashes).

DelKey RegHive, RegKey 'Recursive sub to delete all subkeys and parent key.

Sub DelKey(RegRoot, SPath)
  Dim sKeys()
  Dim SubKeyCount
  Dim objRegistry
  Set objRegistry = GetObject("winmgmts:root\default:StdRegProv")

  lRC = objRegistry.EnumKey(RegRoot, sPath, sKeys)

  If (lRC = 0) And (Err.Number = 0) Then
      for each Key in sKeys
        ' MSGBOX "ENUMERATING KEY: " & sPath & "\" & Key, vbinformation
        DelKey RegRoot, SPath & "\" & Key
      next
      ' MSGBOX "DELETING KEY: " & sPath, vbexclamation
      lRC2 = objRegistry.DeleteKey(RegRoot, sPath)
      If (lRC2 = 0) And (Err.Number = 0) Then
        'msgbox "Success!", vbinformation
      Else
        'msgbox "Error!", vbcritical
      End If
  Else
      MSGBOX "COULDN'T ENUMERATE KEY: " & sPath & "\" & Key, vbcritical
  End If
End Sub

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Wed, 28 Apr 2004 04:47:07 GMT  
 read (all) subkeys of a given registry key ?
' This time without errors...

Option Explicit
On Error Resume Next

Const HKEY_CLASSES_ROOT = &H80000000
Const HKEY_CURRENT_USER = &H80000001
Const HKEY_LOCAL_MACHINE = &H80000002
Const HKEY_USERS = &H80000003
Const HKEY_CURRENT_CONFIG = &H80000005
Const HKEY_DYN_DATA = &H80000006

Dim RegHive
Dim RegKey

'Select registry hive constant from above list.
RegHive = HKEY_CURRENT_USER
'Path to key to delete (no leading/trailing slashes).
RegKey = "Software\Microsoft\Windows\CurrentVersion\Policies"

DelKey RegHive, RegKey 'Recursive sub to delete all subkeys and parent key.
Msgbox "Done!", vbinformation

Sub DelKey(RegRoot, SPath)
  Dim sKeys()
  Dim SubKeyCount
  Dim objRegistry
  Dim lRC
  Dim lRC2
  Dim Key
  Set objRegistry = GetObject("winmgmts:root\default:StdRegProv")

  lRC = objRegistry.EnumKey(RegRoot, sPath, sKeys)

  If (lRC = 0) And (Err.Number = 0) Then
      for each Key in sKeys
        ' MSGBOX "ENUMERATING KEY: " & sPath & "\" & Key, vbinformation
        DelKey RegRoot, SPath & "\" & Key
      next
      ' MSGBOX "DELETING KEY: " & sPath, vbexclamation
      lRC2 = objRegistry.DeleteKey(RegRoot, sPath)
      If (lRC2 = 0) And (Err.Number = 0) Then
        'msgbox "Success!", vbinformation
      Else
        'msgbox "Error!", vbcritical
      End If
  Else
      MSGBOX "COULDN'T ENUMERATE KEY: " & sPath & "\" & Key, vbcritical
  End If
End Sub

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Wed, 28 Apr 2004 04:59:03 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Reading all subkeys of a certain key from registry

2. enumerates subkeys on a registry key

3. Delete registry key with subkeys

4. Help Deleting Registry Keys with subkeys and values

5. How to delete registry key and all subkeys

6. Delete Registry Key with subkeys

7. Deleting Registry KEY with Subkeys

8. How to iterate over registry keys/subkeys

9. Read subkeys from Registry?

10. Reading multiple registry subkeys

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

12. enum registry subkeys using winAPI32 registry functions

 

 
Powered by phpBB® Forum Software