Solved

Read protected registry keys with vb6 using API or Activex control

Posted on 2009-07-10
12
809 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
ID: 24830330
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
ID: 24830862
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
ID: 24887478
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
Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

 
LVL 38

Accepted Solution

by:
PaulHews earned 500 total points
ID: 24907112
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
ID: 31602327
That worked.  Thanks much!
0
 
LVL 38

Expert Comment

by:PaulHews
ID: 24907364
>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
ID: 24907415
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
ID: 24907882
>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
ID: 24908500
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
ID: 24908607
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

In this article you will learn how to create a free basic website on Bitbucket, a git service provider. Polymer creates dynamic HTML components, which allow more flexibility than static HTML. This tutorial uses Ubuntu Linux but can also be done on W…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial will give you a introduction in two parts how to utilize Windows Live Movie Maker to its maximum editing capability. This will be demonstrated using Windows Live Movie Maker on Windows 7 operating system.
The viewer will learn how to successfully download and install the SARDU utility on Windows 7, without downloading adware.

792 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