2

In Microsoft Visual C++ I have the following piece of code to access a path in registry. Then I read a value of key Installed with RegQueryValueEx. So far so good, the value seems to be 1, which corresponds with the presence of Visual C++ 2010 runtime on my system. (it happens to be a piece of code to detect the presence of the c++ runtime).

Now when I check with regedit.exe at HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\10.0 I do not see VC in the tree.

How is this possible? I have copied/pasted all paths and code in this question, so they must be correct.

Code in C++ application:

HKEY RegistryKey;
DWORD ErrorCode;
DWORD RegDwordValue = 0;
DWORD RegDwordValueSize = sizeof(DWORD);
if((ErrorCode = RegOpenKeyExA(HKEY_LOCAL_MACHINE,
                "SOFTWARE\\Microsoft\\VisualStudio\\10.0\\VC\\VCRedist\\x86",
                0, //Reserved
                KEY_READ,
                &RegistryKey)) != ERROR_SUCCESS)
{
    //Either the key does not exists, or registry access is denied. Anyway, detection did not succeed
    std::cout << "Could not read registry path:\n\t" << lpcRegistryPath << "\n\tError code: " << ErrorCode;
    return false;
}
if((ErrorCode = RegQueryValueEx(    RegistryKey,
                                    lpcValueToQuery,
                                    NULL,
                                    NULL,
                                    (LPBYTE)&RegDwordValue,
                                    &RegDwordValueSize
                                    )) != ERROR_SUCCESS)
{
    std::cout << "Could not read registry value, error " << ErrorCode;
    return false;
}

EDIT: I have added an export of the registry below

Windows Registry Editor Version 5.00

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\10.0]

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\10.0\Debugger]
"FEQARuntimeImplDll"="C:\\Program Files\\Microsoft Visual Studio 10.0\\Common7\\Packages\\Debugger\\X64\\Microsoft.VisualStudio.Debugger.Runtime.Impl.dll"

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\10.0\Packages]

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\10.0\Packages\{4A0C6509-BF90-43DA-ABEE-0ABA3A8527F1}]

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\10.0\Packages\{4A0C6509-BF90-43DA-ABEE-0ABA3A8527F1}\Settings]

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\10.0\Packages\{4A0C6509-BF90-43DA-ABEE-0ABA3A8527F1}\Settings\Tools]

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\10.0\Packages\{4A0C6509-BF90-43DA-ABEE-0ABA3A8527F1}\Settings\Tools\SSISScript]
"ScriptLanguage"="CSharp"
Mike de Klerk
  • 11,906
  • 8
  • 54
  • 76
  • 1
    See link in this old answer of [mine](http://stackoverflow.com/questions/14585286/c-regcreatekeyex-success-but-without-result/14585359#14585359) – hmjd Feb 14 '13 at 15:08

1 Answers1

6

What you describe happens if you are on a 64-bit system running a 32-bit app that is affected by either Registry Redirection or Registry Virtualization. If your VC++ app is 32-bit and you are running the 64-bit version of regedit, or your app is 64-bit and you are running the 32-bit version of regedit, then they will effectively be viewing/manipulating different areas of the Registry. That would explain why they do not see each other's data.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • Yes thats it! http://support.microsoft.com/kb/305097 shows me that 32 bit registry keys are located in HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node Now the full path is HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\10.0\VC Thanks for the quick help!! – Mike de Klerk Feb 14 '13 at 15:10