Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enumerating Registries that contain a subkey named Control 1

Status
Not open for further replies.
Sep 29, 2002
524
US
Hello,

WARNING: I have no idea how to script but I have been trying to come up with the code that I need but seem to be stuck here because this does not output anything.
Code:
Const ForReading = 1, ForWriting = 2

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

strComputer = "."
strKeyPath = "CLSID"

Dim fso, Myfile
Set fso = CreateObject("Scripting.FileSystemObject")
Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_ 
strComputer & "\root\default:StdRegProv")

' Open the file for write access.
On Error Resume Next
Set MyFile = fso.OpenTextFile("c:\temp\testfile.txt", ForWriting, True, OpenAsASCII)

objReg.EnumKey HKEY_CLASSES_ROOT, strKeyPath, arrSubKeys

For Each subkey In arrSubKeys
  Write subkey
Next

objFile.Close

Basically, I would like to write a script that lists the CLSID, PROGID and version values of all the subkeys under HKEY_CLASS_ROOT\CLSID where a HKEY_CLASS_ROOT\CLSID\<CLSID>\CONTROL exist. How do I do this?

Thanks in advanced,

Gladys Rodriguez
GlobalStrata Solutions
Computer Repair, Website Design and Computer Consultant
Small Business Resources
Anime, Manga and Video Games
 
Get rid of the On Error Resume Next and see what error you get.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
haha. Got it. Thanks. Just the small things ...

Code:
Const ForReading = 1, ForWriting = 2

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

strComputer = "."
strKeyPath = "CLSID"

Dim fso, Myfile
Set fso = CreateObject("Scripting.FileSystemObject")
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_ 
strComputer & "\root\default:StdRegProv")

' Open the file for write access.
On Error Resume Next
Set MyFile = fso.OpenTextFile("c:\temp\testfile.txt", ForWriting, True, OpenAsASCII)

objReg.EnumKey HKEY_CLASSES_ROOT, strKeyPath, arrSubKeys

For Each subkey In arrSubKeys
  MyFile.WriteLine subkey
Next


Gladys Rodriguez
GlobalStrata Solutions
Computer Repair, Website Design and Computer Consultant
Small Business Resources
Anime, Manga and Video Games
 
I don't think my contribution was worth a star, but thank you and I'm glad to hear you worked it out.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 

Ok. Since you insist :)

I have gotten to the point that I am able to list the keys under HKEY_CLASSES\CLSID and the subkeys of those keys. However, I am not sure how to break out of a loop once I find the subkey named CONTROL.

For Example. Out of all of these:
Code:
CLSID\{01E2E7C0-2343-407f-B947-7E132E791D3E}
  InProcServer32
CLSID\{021003e9-aac0-4975-979f-14b5d4e717f8}
  InProcServer32
CLSID\{027713F2-5FA8-11d2-875B-00A0C93C09B3}
  Control
  InprocServer32
  MiscStatus
  Programmable
  ToolboxBitmap32
  TypeLib
  Version
CLSID\{0285b5c0-12c7-11ce-bd31-00aa004bbb1f}
  InprocServer32

I want to print to the file only:
Code:
CLSID\{027713F2-5FA8-11d2-875B-00A0C93C09B3}

and some of its subkeys, since it has the CONTROL subkey under it.

This is the code I have so far:
Code:
Const ForReading = 1, ForWriting = 2

Const HKEY_CLASSES_ROOT 	= &H80000000

strComputer = "."
strKeyPath = "CLSID"

Dim fso, Myfile
Set fso = CreateObject("Scripting.FileSystemObject")
Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_ 
strComputer & "\root\default:StdRegProv")
Set objReg2=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_ 
strComputer & "\root\default:StdRegProv")

' Open the file for write access.
Set MyFile = fso.OpenTextFile("c:\temp\testfile.txt", ForWriting, True, OpenAsASCII)

objReg.EnumKey HKEY_CLASSES_ROOT, strKeyPath, arrSubKeys

For Each subkey In arrSubKeys
  strKeyPath2 = strKeyPath & "\" & subkey

  IF strKeyPath2 <> "CLSID\CLSID" THEN
    Myfile.Writeline strKeyPath2

    On Error Resume Next
    objReg2.EnumKey HKEY_CLASSES_ROOT, strKeyPath2, arrSubKeys2

    For Each subkey2 In arrSubKeys2
      Myfile.Writeline "  " & subkey2
    NEXT

  END IF
Next

Thanks in advanced,


Gladys Rodriguez
GlobalStrata Solutions
Computer Repair, Website Design and Computer Consultant
Small Business Resources
Anime, Manga and Video Games
 
A starting point:
Code:
...
objReg.EnumKey HKEY_CLASSES_ROOT, strKeyPath, arrSubKeys
For Each subkey In arrSubKeys
  strKeyPath2 = strKeyPath & "\" & subkey
  If Left(strKeyPath2,7) = "CLSID\{" Then
    objReg2.EnumKey HKEY_CLASSES_ROOT, strKeyPath2, arrSubKeys2
    bControl = False
    For Each subkey2 In arrSubKeys2
      If subkey2 = "Control" Then
        bControl = True
        Exit For
      End If
    Next
    If bControl Then
      Myfile.Writeline strKeyPath2
      For Each subkey2 In arrSubKeys2
        Myfile.Writeline "  " & subkey2
      Next
    End If
  End If
Next

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top