RegOpenKeyEx returns access denied (error 5)


S

Strigger

Hi,

I'm running under a user that is a member of the
admistrators group and trying to retrieve a registry key
value, using this code:

Private Declare Function RegOpenKeyEx Lib "advapi32.dll"
Alias "RegOpenKeyExA" _
(ByVal lngHKey As Long, ByVal lpSubKey As String, ByVal _
lpReserved As Long, samDesired As Long, phkResult As Long)
As Long

Private Const HKEY_CURRENT_USER = &H80000001
Private Const KEY_QUERY_VALUE = &H1
Private Const KEY_READ = &H19
Private Const KEY_ALL_ACCESS = &H3F

Dim lngReturn As Long

lngReturn = RegOpenKeyEx(HKEY_CURRENT_USER, "Site", 0,
KEY_QUERY_VALUE, myPtr)

but I keep getting ACCESS DENIED (lngReturn=5)!
Any ideas what causes this problem?
(I have tried KEY_READ & KEY_ALL_ACCESS too but without
any luck)

Any suggestions?
Strigger
 
Ad

Advertisements

M

Marco

I suggest that you check the ACL on the key using regedt32 or regedit (under
XP they are the same). I don't have that key on my system so I can't tell.

Cheers,

Marco
www.neovalens.com
 
S

Strigger

Believe me, I have tried almost everything, including
changing the permissions on this specific key.

You can add a key of your own, change the code accordingly
and run it... I'd appreciate it if you tell me what went
on with your computer.

Strigger
 
Ad

Advertisements

Joined
Mar 12, 2012
Messages
1
Reaction score
0
I am aware the thread is very old.
I had the same problem and I reached this topic searching Google for a solution.
So maybe it will help some else.

In my case, the solution has been to move the call to RegOpenKeyEx to a .bas external module.
So in the form .frm source code file, I have put the call to the sub defined in the other .bas module.
I am sure about this, because as soon as I move the call to RegOpenKeyEx back in the .frm file, the problem (error returned 5) reappears.

I must say, I am a beginner in VB6. I do not have a technical explanation as to why that happens.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top