tags:

views:

284

answers:

3

Hello,

I m developing a tool in VC++ which fetches system information for Windows 7: Here is the sample code snippet:

 CRegKey key;
if(ERROR_SUCCESS == key.Open(hKey, pPath, KEY_READ))
{
    // read the value, length will contain the size after the call
    if (ERROR_SUCCESS != key.QueryBinaryValue(pValueName, pData, &length))
    {
        // error occurred
        length = 0;
    }
 key.Close();
}   
else
{
 length = 0;
}

length returned is 0. :( QueryBinaryValue() method which tries to read REG_BINARY key from registry is not working properly for windows 7 and thowing error code as 2( key not found). The same code works well for XP, Vista.

waiting for the quick reply. Thanks in advance.

A: 

Have you checked that both the key and value exist in the Windows 7 registry by another route (e.g. RegEdit)?

Process Monitor might show up the underlying problem. Specifically exactly what is failing.

Without knowing the key/value you are trying to access hard to be more specific.

Richard
A: 

Yes buddy, both the keys and values exists in Vista, XP, Windows 7. But its not working only with Windows 7

A: 

Two things to look into:

  1. Is it possible insufficiante permissions are preventing you from opening the key on 7? IIRC, Process Monitor (suggested by Richard) would show you the reason of the failure, including whether the access was denied.
  2. 64 bit versions of Windows contain a sub-system for 32 bit executables. These executables see a different view of the system folder (SysWOW64, instead of System32) and a different view of the registry. If 7 is 64 bit and your app is 32 bit, it is possible you and your app are not looking at the same registry hives - when you run regedit, you're watching the main 64 bit registry. However, a 32 bit executable would be looking at the WOW hives. If this seems to be the case, you can use the regedit that's under SysWOW64. Being a 32 bit executable, it will show you exactly what your app sees.
eran