#define PATH "HKEY_LOCAL_MACHINE\\Software\\..."
HKEY hk;
if(RegOpenKey(
HKEY_LOCAL_MACHINE,
PATH,
//0,
//KEY_ALL_ACCESS =>KEY_QUERY_VALUE,
&hk) != ERROR_SUCCESS)
{
return FALSE;
}
DWORD dwType = 0;
unsigned char szBuff[1024];
DWORD dwBuffLength = sizeof(szBuff);
if (RegQueryValueEx(hk, "InstallPath", 0, &dwType, szBuff, &dwBuffLength) != ERROR_SUCCESS)
{
return FALSE;
}
if(dwType != REG_SZ)
{
return FALSE;
}
return TRUE;
使用记录:
1)以前RegOpenKeyEx没有试成功,原来是要用KEY_QUERY_VALUE,而不能用KEY_ALL_ACCESS
2)当dwBuffLength传入比获得的字符串长度小的值时,会失败。所以建议传大一些的值,调用后它会将该变量重新设为获得的字符串长度。
-----------------------------------
下面是从wix的wcalog.cpp中的一段:
static BOOL IsVerboseLogging()
{
static int iVerbose = -1;
if (0 > iVerbose)
{
iVerbose = WcaIsPropertySet("LOGVERBOSE");
if (0 == iVerbose) // if the
property wasn't set, check the registry to see if the logging policy
was turned on
{
HKEY hkey = NULL;
WCHAR rgwc[16] = { 0 };
DWORD cb = sizeof(rgwc);
if
(ERROR_SUCCESS == ::RegOpenKeyExW(HKEY_LOCAL_MACHINE,
L"Software\\Policies\\Microsoft\\Windows\\Installer", 0,
KEY_QUERY_VALUE, &hkey))
{
if (ERROR_SUCCESS == ::RegQueryValueExW(hkey,
L"Logging", 0, NULL, reinterpret_cast<BYTE*>(rgwc), &cb))
{
for (LPCWSTR pwc = rgwc; (cb /
sizeof(WCHAR)) > static_cast<DWORD>(pwc - rgwc) &&
*pwc; pwc++)
{
if (L'v' ==
*pwc || L'V' == *pwc)
{
iVerbose = 1;
break;
}
}
}
::RegCloseKey(hkey);
}
}
}
Assert(iVerbose >= 0);
return (BOOL)iVerbose;
}