Windows >
Software Development for Windows Client Forums
>
Application Compatibility for Windows Development
>
Reading from Registry in Win7 not compatible.
Reading from Registry in Win7 not compatible.
- HI
I have VBA code that reads and writes to the registry key. The code works fine on all versions of Windows prior to Win 7. In Win 7 the write is working fine but the read can't open the key
ret = RegOpenKeyExA(MainKey, SubKey, 0&, KEY_READ, lpHKey)
Any suggestions? HELP
Answers
- Hello,When the code does not work, what error message you got?I perform a test on Windows 7 x86 version and it worked well on my box. Please try it and let me know whether it works for you.<code>Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" _(ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As _Long, ByVal samDesired As Long, phkResult As Long) As LongPrivate Const HKEY_CURRENT_USER = &H80000001Private Const READ_CONTROL = &H20000Private Const KEY_QUERY_VALUE = &H1Private Const KEY_ENUMERATE_SUB_KEYS = &H8Private Const KEY_NOTIFY = &H10Private Const SYNCHRONIZE = &H100000Private Const STANDARD_RIGHTS_READ = (READ_CONTROL)Private Const KEY_READ = ((STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And (Not SYNCHRONIZE))Sub test()Dim KeyName As String, handle As LongKeyName = "Software\Microsoft"r = RegOpenKeyEx(HKEY_CURRENT_USER, KeyName, 0, KEY_READ, handle)MsgBox rEnd Sub</code>Since you are reading registry keys, you might also check the key that you read to make sure the current user have the permission.Thanks,Rong-Chun Zhang
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.- Marked As Answer byRong-Chun ZhangMSFT, ModeratorMonday, November 16, 2009 1:22 PM
All Replies
- Hello,When the code does not work, what error message you got?I perform a test on Windows 7 x86 version and it worked well on my box. Please try it and let me know whether it works for you.<code>Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" _(ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As _Long, ByVal samDesired As Long, phkResult As Long) As LongPrivate Const HKEY_CURRENT_USER = &H80000001Private Const READ_CONTROL = &H20000Private Const KEY_QUERY_VALUE = &H1Private Const KEY_ENUMERATE_SUB_KEYS = &H8Private Const KEY_NOTIFY = &H10Private Const SYNCHRONIZE = &H100000Private Const STANDARD_RIGHTS_READ = (READ_CONTROL)Private Const KEY_READ = ((STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And (Not SYNCHRONIZE))Sub test()Dim KeyName As String, handle As LongKeyName = "Software\Microsoft"r = RegOpenKeyEx(HKEY_CURRENT_USER, KeyName, 0, KEY_READ, handle)MsgBox rEnd Sub</code>Since you are reading registry keys, you might also check the key that you read to make sure the current user have the permission.Thanks,Rong-Chun Zhang
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.- Marked As Answer byRong-Chun ZhangMSFT, ModeratorMonday, November 16, 2009 1:22 PM
- Hello,Have you got any progress on this issue? If there is anything else we can help, welcome to post here.Thanks,Rong-Chun Zhang
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.


