Solved

Read protected registry keys with vb6 using API or Activex control

Posted on 2009-07-10
12
804 Views
Last Modified: 2013-11-18
Need to read this key and its subkeys, but have not been able to.  Using VB6, tried using API calls, and several registry management activex controls.  Nothing seems to work.  Here's the key I'm trying to get to:
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Enum\USBSTOR

I can read up to ...\ControlSet and some of its subkeys, but can't read ...\Enum  or ...\Enum\USBSTOR.  I only want to read these keys and subkeys, do not want to change anything.  Can read all of them no problem with regedit, but I need to do this with my program, on the users computer with could be xp up.

If there is a VB6 activex that does this, I have no problem paying for it.  The only one I've found  that *might* work is from Eltima Software:
http://www.eltima.com/products/registry-activex/
...which has a read key parameter they claim takes the R/O flag, but I can't get it to work, and tech support from this overseas company only gets me a sales rep who can't do more than ask dumb obvious questions, with 24+ hr turnaround.

Is this solvable?
0
Comment
Question by:xbeemer
  • 5
  • 3
  • 2
12 Comments
 
LVL 29

Expert Comment

by:matrixnz
Comment Utility
The following works for me fine
const HKEY_LOCAL_MACHINE = &H80000002

strComputer = "."

 

Set oReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" &_ 

strComputer & "\root\default:StdRegProv")

 

strKeyPath = "SYSTEM\CurrentControlSet\Enum\USBSTOR"

oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys

 

For Each subkey In arrSubKeys

    WScript.Echo subkey

Next

Open in new window

0
 

Author Comment

by:xbeemer
Comment Utility
Thanks for the reply....but I don't get it.  Could you, as they say at the spelling bee, use it in a sentence?  Maybe wrap it in a

Private Sub Command1_Click()

End Sub

...and especially indicate what the Set GetObject refers to?  My VB6 IDE thinks it should be printed in red.
0
 

Author Comment

by:xbeemer
Comment Utility
I responded to this a week ago, asking for clarification.  Still no response from the "experts."  Or anyone else (I also emailed support).  This looked like a good service at first, well worth the subscription price.  But the lack of response to the one and only issue I requested help on (and assigned my max points to), leaves me feeling Experts Exchange is all hat and no cattle.
0
 
LVL 38

Accepted Solution

by:
PaulHews earned 500 total points
Comment Utility
The reason the code posted above looks alien is because it's VBScript, not Visual Basic 6.  Here's the same code with suitable declarations so that it compiles and runs in VB6.  
Option Explicit
 

Private Sub Command1_Click()

    Const HKEY_LOCAL_MACHINE = &H80000002

    Dim strComputer As String

    Dim strKeyPath As String

    Dim oReg As Object

    Dim arrSubKeys As Variant

    Dim SubKey As Variant

    

    strComputer = "."

    

 

    Set oReg = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _

    strComputer & "\root\default:StdRegProv")

 

    strKeyPath = "SYSTEM\CurrentControlSet\Enum\USBSTOR"

    oReg.EnumKey HKEY_LOCAL_MACHINE, strKeyPath, arrSubKeys

 

    For Each SubKey In arrSubKeys

        Debug.Print SubKey

    Next
 

End Sub

Open in new window

0
 

Author Closing Comment

by:xbeemer
Comment Utility
That worked.  Thanks much!
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 38

Expert Comment

by:PaulHews
Comment Utility
>That worked. Thanks much!

You're welcome.  I think it would have been more appropriate to split the points (as I was elaborating on the other expert's code.)  I will request this from the moderator team.  
0
 

Author Comment

by:xbeemer
Comment Utility
Maybe, if he had responded to my message requesting clarification over a week ago.  I was about to bail, thinking this was a rip off service.  The other expert did no one any good.
jd
0
 
LVL 38

Expert Comment

by:PaulHews
Comment Utility
>The other expert did no one any good.

Well, the other expert provided the code.  My alterations were very minor.  As to why the expert never followed up, well there could be many good reasons for that.   We are all volunteers here, and real life takes priority.

The other expert took the time to research, test the code (it would work in VBScript) and post it.  My feeling is that that contribution should be recognized, even if he didn't stick around to follow up.
0
 

Author Comment

by:xbeemer
Comment Utility
OK.  I disagree, but it's your call.  Do as you like.  And thanks again for the help.
0
 
LVL 29

Expert Comment

by:matrixnz
Comment Utility
Sorry for not following up, we're in the middle of a merger at work so don't have as much time as I had in the past.  To be honest I actually didn't see you had responded, may of accidentally deleted the response message.  Anyway I'm happy for the points to stay with Paul, glad it's sorted, thanks Paul you're a scholar and a gentleman. =)

Cheers
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
When you start your Windows 10 PC and got an "Operating system not found" error or just saw  "Auto repair for startup". After a while, you have entered a loop for Auto repair which does not fix anything and you will be in a  panic as all your work w…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now