tags:

views:

25

answers:

1

I would like to check if .NET 3.5 Framework is installed by reading the "Install" value of the key "Software\Microsoft\NET Framework Setup\NDP\v3.5". I am very happy to find out that there is an MFC class CSettingStore that can do the job easily but I found out the CSettingStore.Open always return false.

The code is as follow:

bool bOpen = reg.Open(_T("Software\\Microsoft\\NET Framework Setup\\NDP\\v3.5"));
if (bOpen && reg.Read (_T("Install"), dwInstall))
{
    return dwInstall == 1;
}

In this case, reg.Open always return false.

Anything wrong with the code?

+1  A: 

In http://msdn.microsoft.com/en-us/library/bb982796.aspx I read:

<quote>

The meaning of bAdmin is reversed Actually, if bAdmin is true, the key is HKEY_LOCAL_MACHINE and, if it's false, the key is HKEY_CURRENT_USER. You can see this for yourself in afxsettingsstore.cpp:

CSettingsStore::CSettingsStore(BOOL bAdmin, BOOL bReadOnly) :
m_bReadOnly(bReadOnly), m_bAdmin(bAdmin), m_dwUserData(0)
{
m_reg.m_hKey = bAdmin ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER;
}

</quote>

So it looks like a documentation bug. Does CSettingsStore reg (TRUE, TRUE); work better?

usta
Thank yo so much. Exactly the documentation bug. I use CSettingsStore reg (TRUE, TRUE) now and it works.
david.healed