PC Review


Reply
Thread Tools Rating: Thread Rating: 5 votes, 3.40 average.

RegOpenKeyEx returns access denied (error 5)

 
 
Strigger
Guest
Posts: n/a
 
      1st May 2004
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

 
Reply With Quote
 
 
 
 
Marco
Guest
Posts: n/a
 
      1st May 2004
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

"Strigger" <(E-Mail Removed)> wrote in message
news:707a01c42f90$2b3d24c0$(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
 
 
 
Strigger
Guest
Posts: n/a
 
      1st May 2004
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

>-----Original Message-----
>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
>
>"Strigger" <(E-Mail Removed)> wrote in

message
>news:707a01c42f90$2b3d24c0$(E-Mail Removed)...
>> 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
>>

>
>
>.
>

 
Reply With Quote
 
Marco
Guest
Posts: n/a
 
      2nd May 2004
Hi

I guess that the problem lies somewhere in your code. Check out the VB
sample on M$
http://support.microsoft.com/default...b;en-us;186428

Hope it helps ..

Ciao

Marco

--
Execute applications with elevated privileges [ www.neovalens.com ]
--



"Strigger" <(E-Mail Removed)> wrote in message
news:707a01c42f90$2b3d24c0$(E-Mail Removed)...
> 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
>



 
Reply With Quote
 
New Member
Join Date: Mar 2012
Posts: 1
 
      12th Mar 2012
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.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
RegOpenKeyEx() returns 2 from second time onwords RAG Windows XP Help 0 19th Feb 2007 05:20 PM
Access denied ! Access Denied ! Access Denied! =?Utf-8?B?Y2hyaXNncnVudGxlZA==?= Windows Vista Administration 9 10th Jul 2006 05:04 PM
RegOpenKeyEx() returns Status 1450 =?Utf-8?B?cmZlbmdpbmVlcg==?= Microsoft Windows 2000 Registry 0 2nd Feb 2006 10:50 PM
Web Service -> ActiveX DLL -> RegOpenKeyEx -> NO ACCESS!!! sdz602 Microsoft C# .NET 3 2nd Mar 2004 03:24 AM
Receiving error when clicking on properties: RegOpenKeyEx:Handle is invalid Assassin Windows XP Accessibility 3 27th Sep 2003 07:31 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:27 AM.