4

I have a registry entry I can't seem to read in C++, but it shows up in Regedit.

Using the following C++ snippet:

openResult=RegOpenKeyEx( HKEY_LOCAL_MACHINE, _TEXT("SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v4\\Full"), 0, KEY_READ, &root); readResult1=RegQueryValueEx(root, _TEXT("InstallPath"), NULL, NULL, data1, &size); readResult2=RegQueryValueEx(root, _TEXT("fake_entry"), NULL, NULL, data2, &size); 

I get Error 2, ERROR_FILE_NOT_FOUND for my second RegQueryValueEx() call.

As you can see in the image below, my fake_entry exists.

enter image description here

I created this entry via Regedit.

Microsoft's Registry Keys Affected by WOW64 does not include the location I'm trying to read, and as you can see in the picture below, my fake_entry is not in the Wow6432Node location.

enter image description here

  • Yes, I understand this isn't a registry location I should be changing. I stumbled upon this as I was debugging my code and am curious why my added fake_entry doesn't work.
  • Yes, I've read about Registry Redirector.
  • Yes, I've read this question.
  • Yes, I tried reading fake_entry at SOFTWARE\\Wow6432Node\\Microsoft\\NET Framework Setup\\NDP\\v4\\Full with the same error.

Running Windows 7, 64 bit, C++ in Visual Studio 2010, using ASCII character encoding.

Am I misunderstanding the Registry Redirector? Is there a problem with my code? Are there some sort of permission settings on certain portions of the Registry? I'm obviously missing something. Please point me in the right direction.

2 Answers 2

2

Try

openResult = RegOpenKeyEx( HKEY_LOCAL_MACHINE, _TEXT("SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v4\\Full"), 0, KEY_READ|KEY_WOW64_64KEY, &root); 

according to MSDN you should use either KEY_WOW64_64KEY or KEY_WOW64_32KEY for WOW64 access

Sign up to request clarification or add additional context in comments.

Comments

2

You are misreading the table of keys affected by WOW64. From the very top of that page:

The following table lists registry keys that are redirected, shared by both 32-bit and 64-bit applications, or redirected and reflected on 64-bit Windows. Subkeys of the keys in this table inherit the parent key's behavior unless otherwise specified. If a key has no parent listed in this table, the key is shared.

The parent of your key is HKLM\Software which is redirected. So your key is also redirected. It inherits that from its parent, as the documentation that I quoted explains.

You'll need to read the 64 bit view using KEY_WOW64_64KEY.

7 Comments

Thank you for your correct answer David. Any idea why I have to read my fake_entry before InstallPath for it to work? (See updated question).
You've already accepted the other answer, which makes no real effort to explain things. Just gives you code and no insight. But you ask me for onward help. Why ask me? Why not ask the other answerer? I'm curious as to the thinking behind all that. In any case, I think the onward question deserves a new question. I'd rather you reverted this question to its original form, and asked a new question.
His arrived just before yours, and it did work. Plus, with your reputation, I thought you might know off the top of your head. I apologize if I've offended.
No offence taken at all. I just feel quite strongly that askers should accept the best answer rather than the fastest answer. Accepting the fastest answer just encourages people to write short code only answers that don't offer insight. I think askers should reward the extra effort involved in explaining and discussing the topic. That's my opinion though. Since it's your question, you are welcome to accept whatever you wish, and so please don't view this as me pressuring you to change accept. I just wanted to make that point.
As for the follow-up question, I really feel it should be in a new question. And this one should be reverted to its original form.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.