2002-09-03 18:44:19 +00:00
|
|
|
/* $Id: RegistryKey.cpp,v 1.6 2002/09/03 18:44:18 chorns Exp $
|
2000-10-04 21:04:31 +00:00
|
|
|
*
|
|
|
|
* regexpl - Console Registry Explorer
|
|
|
|
*
|
2001-01-13 23:55:37 +00:00
|
|
|
* Copyright (C) 2000,2001 Nedko Arnaoudov <nedkohome@atia.com>
|
2000-10-04 21:04:31 +00:00
|
|
|
*
|
2000-10-24 20:17:42 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
2000-10-04 21:04:31 +00:00
|
|
|
*
|
2000-10-24 20:17:42 +00:00
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
2000-10-04 21:04:31 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
// RegistryKey.cpp: implementation of the CRegistryKey class.
|
|
|
|
//
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "ph.h"
|
|
|
|
#include "RegistryKey.h"
|
|
|
|
|
2001-01-10 01:25:29 +00:00
|
|
|
static TCHAR *g_ppszHiveNames[] =
|
|
|
|
{
|
|
|
|
_T("HKEY_CLASSES_ROOT"),
|
|
|
|
_T("HKEY_CURRENT_USER"),
|
|
|
|
_T("HKEY_LOCAL_MACHINE"),
|
|
|
|
_T("HKEY_USERS"),
|
|
|
|
_T("HKEY_PERFORMANCE_DATA"),
|
|
|
|
_T("HKEY_CURRENT_CONFIG"),
|
|
|
|
_T("HKEY_DYN_DATA")
|
|
|
|
};
|
|
|
|
|
2000-10-04 21:04:31 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
// Construction/Destruction
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
2001-01-10 01:25:29 +00:00
|
|
|
CRegistryKey::CRegistryKey()
|
|
|
|
{
|
|
|
|
m_pszKeyName = NULL;
|
|
|
|
m_pszMachineName = NULL;
|
|
|
|
m_CurrentAccess = 0;
|
|
|
|
m_hKey = NULL;
|
|
|
|
}
|
|
|
|
|
2002-09-03 18:44:19 +00:00
|
|
|
HRESULT CRegistryKey::InitRoot(const TCHAR *pszMachineName)
|
2001-01-10 01:25:29 +00:00
|
|
|
{
|
|
|
|
if ((pszMachineName)&&
|
|
|
|
((_tcslen(pszMachineName) < 3)||
|
|
|
|
(pszMachineName[0] != _T('\\'))||
|
|
|
|
(pszMachineName[1] != _T('\\'))
|
|
|
|
)
|
|
|
|
)
|
|
|
|
{
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT hr = Uninit();
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
if (pszMachineName)
|
|
|
|
{ // copy machine name
|
|
|
|
size_t size = _tcslen(pszMachineName);
|
|
|
|
|
|
|
|
m_pszMachineName = new TCHAR [size+2];
|
|
|
|
if (!m_pszMachineName)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
_tcscpy(m_pszMachineName,pszMachineName);
|
|
|
|
m_pszMachineName[size] = _T('\\');
|
|
|
|
m_pszMachineName[size+1] = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_pszMachineName = NULL; // local registry
|
|
|
|
}
|
|
|
|
|
|
|
|
ASSERT(m_pszKeyName == NULL);
|
|
|
|
m_CurrentAccess = 0;
|
|
|
|
ASSERT(m_hKey == NULL);
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT CRegistryKey::Init(HKEY hKey, const TCHAR *pszPath, const TCHAR *pszKeyName, REGSAM CurrentAccess)
|
|
|
|
{
|
|
|
|
HRESULT hr = Uninit();
|
|
|
|
if (FAILED(hr))
|
|
|
|
return hr;
|
|
|
|
|
|
|
|
if (!pszKeyName || !hKey)
|
|
|
|
return E_INVALIDARG;
|
|
|
|
|
|
|
|
// copy key name name
|
|
|
|
size_t size = _tcslen(pszKeyName);
|
|
|
|
if (pszPath)
|
|
|
|
size += _tcslen(pszPath);
|
|
|
|
|
|
|
|
m_pszKeyName = new TCHAR [size+2];
|
|
|
|
if (!m_pszKeyName)
|
|
|
|
return E_OUTOFMEMORY;
|
|
|
|
_stprintf(m_pszKeyName,_T("%s%s\\"),pszPath?pszPath:_T(""),pszKeyName);
|
|
|
|
|
|
|
|
m_CurrentAccess = CurrentAccess;
|
|
|
|
m_hKey = hKey;
|
|
|
|
ASSERT(m_hKey);
|
2000-10-04 21:04:31 +00:00
|
|
|
|
2001-01-10 01:25:29 +00:00
|
|
|
return S_OK;
|
2000-10-04 21:04:31 +00:00
|
|
|
}
|
|
|
|
|
2001-01-10 01:25:29 +00:00
|
|
|
HRESULT CRegistryKey::Uninit()
|
2000-10-04 21:04:31 +00:00
|
|
|
{
|
2001-01-10 01:25:29 +00:00
|
|
|
if (m_pszKeyName)
|
|
|
|
{
|
|
|
|
delete [] m_pszKeyName;
|
|
|
|
m_pszKeyName = NULL;
|
|
|
|
}
|
2000-10-04 21:04:31 +00:00
|
|
|
|
2001-01-10 01:25:29 +00:00
|
|
|
if (m_pszMachineName)
|
|
|
|
{
|
|
|
|
delete [] m_pszMachineName;
|
|
|
|
m_pszMachineName = NULL;
|
|
|
|
}
|
2000-10-04 21:04:31 +00:00
|
|
|
|
2001-01-10 01:25:29 +00:00
|
|
|
LONG nError = ERROR_SUCCESS;
|
|
|
|
if((m_hKey != NULL)&&(!IsHive(m_hKey)))
|
|
|
|
nError = RegCloseKey(m_hKey);
|
|
|
|
|
|
|
|
m_hKey = NULL;
|
|
|
|
|
|
|
|
return (nError == ERROR_SUCCESS)?S_OK:E_FAIL;
|
2000-10-04 21:04:31 +00:00
|
|
|
}
|
|
|
|
|
2001-01-10 01:25:29 +00:00
|
|
|
BOOL CRegistryKey::IsHive(HKEY hKey)
|
2000-10-04 21:04:31 +00:00
|
|
|
{
|
2001-01-10 01:25:29 +00:00
|
|
|
return ((hKey == HKEY_CLASSES_ROOT)||
|
|
|
|
(hKey == HKEY_CURRENT_USER)||
|
|
|
|
(hKey == HKEY_LOCAL_MACHINE)||
|
|
|
|
(hKey == HKEY_USERS)||
|
|
|
|
(hKey == HKEY_PERFORMANCE_DATA)||
|
|
|
|
(hKey == HKEY_CURRENT_CONFIG)||
|
|
|
|
(hKey == HKEY_DYN_DATA));
|
2000-10-04 21:04:31 +00:00
|
|
|
}
|
|
|
|
|
2001-01-10 01:25:29 +00:00
|
|
|
CRegistryKey::~CRegistryKey()
|
2000-10-04 21:04:31 +00:00
|
|
|
{
|
2001-01-10 01:25:29 +00:00
|
|
|
Uninit();
|
|
|
|
}
|
|
|
|
|
|
|
|
const TCHAR * CRegistryKey::GetKeyName()
|
|
|
|
{
|
|
|
|
return m_pszKeyName?m_pszKeyName:(m_pszMachineName?m_pszMachineName:_T("\\"));
|
|
|
|
}
|
|
|
|
|
|
|
|
BOOL CRegistryKey::IsRoot()
|
|
|
|
{
|
|
|
|
return m_hKey == NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
LONG CRegistryKey::OpenSubkey(REGSAM samDesired, const TCHAR *pszSubkeyName, HKEY &rhKey)
|
|
|
|
{
|
|
|
|
if (m_hKey == NULL)
|
|
|
|
{ // subkey of root key is hive root key.
|
|
|
|
if ((_tcsicmp(pszSubkeyName,_T("HKCR")) == 0)||
|
|
|
|
(_tcsicmp(pszSubkeyName,_T("HKEY_CLASSES_ROOT")) == 0))
|
|
|
|
{
|
|
|
|
rhKey = HKEY_CLASSES_ROOT;
|
|
|
|
|
|
|
|
if (m_pszMachineName)
|
|
|
|
return ERROR_FILE_NOT_FOUND;
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
else if ((_tcsicmp(pszSubkeyName,_T("HKCU")) == 0)||
|
|
|
|
(_tcsicmp(pszSubkeyName,_T("HKEY_CURRENT_USER")) == 0))
|
|
|
|
{
|
|
|
|
rhKey = HKEY_CURRENT_USER;
|
|
|
|
|
|
|
|
if (m_pszMachineName)
|
|
|
|
return ERROR_FILE_NOT_FOUND;
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
else if ((_tcsicmp(pszSubkeyName,_T("HKLM")) == 0)||
|
|
|
|
(_tcsicmp(pszSubkeyName,_T("HKEY_LOCAL_MACHINE")) == 0))
|
|
|
|
{
|
|
|
|
rhKey = HKEY_LOCAL_MACHINE;
|
|
|
|
|
|
|
|
if (m_pszMachineName)
|
|
|
|
return RegConnectRegistry(m_pszMachineName,rhKey,&rhKey);
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
else if ((_tcsicmp(pszSubkeyName,_T("HKU")) == 0)||
|
|
|
|
(_tcsicmp(pszSubkeyName,_T("HKEY_USERS")) == 0))
|
|
|
|
{
|
|
|
|
rhKey = HKEY_USERS;
|
|
|
|
|
|
|
|
if (m_pszMachineName)
|
|
|
|
return RegConnectRegistry(m_pszMachineName,rhKey,&rhKey);
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
else if ((_tcsicmp(pszSubkeyName,_T("HKPD")) == 0)||
|
|
|
|
(_tcsicmp(pszSubkeyName,_T("HKEY_PERFORMANCE_DATA")) == 0))
|
|
|
|
{
|
|
|
|
rhKey = HKEY_PERFORMANCE_DATA;
|
|
|
|
|
|
|
|
if (m_pszMachineName)
|
|
|
|
return RegConnectRegistry(m_pszMachineName,rhKey,&rhKey);
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
else if ((_tcsicmp(pszSubkeyName,_T("HKDD")) == 0)||
|
|
|
|
(_tcsicmp(pszSubkeyName,_T("HKEY_DYN_DATA")) == 0))
|
|
|
|
{
|
|
|
|
rhKey = HKEY_DYN_DATA;
|
|
|
|
|
|
|
|
if (m_pszMachineName)
|
|
|
|
return RegConnectRegistry(m_pszMachineName,rhKey,&rhKey);
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
else if ((_tcsicmp(pszSubkeyName,_T("HKCC")) == 0)||
|
|
|
|
(_tcsicmp(pszSubkeyName,_T("HKEY_CURRENT_CONFIG")) == 0))
|
|
|
|
{
|
|
|
|
rhKey = HKEY_CURRENT_CONFIG;
|
|
|
|
|
|
|
|
if (m_pszMachineName)
|
|
|
|
{
|
|
|
|
TCHAR *pch = m_pszMachineName;
|
|
|
|
while (*pch)
|
|
|
|
pch++;
|
|
|
|
pch--;
|
|
|
|
|
|
|
|
ASSERT(*pch == _T('\\'));
|
|
|
|
if (*pch != _T('\\'))
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
|
|
|
|
*pch = 0;
|
|
|
|
|
|
|
|
LONG nError = RegConnectRegistry(m_pszMachineName,rhKey,&rhKey);
|
|
|
|
|
|
|
|
*pch = _T('\\');
|
|
|
|
|
|
|
|
return nError;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return ERROR_FILE_NOT_FOUND;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return RegOpenKeyEx(m_hKey,pszSubkeyName,0,samDesired,&rhKey);
|
|
|
|
}
|
|
|
|
|
|
|
|
LONG CRegistryKey::OpenSubkey(REGSAM samDesired, const TCHAR *pszSubkeyName, CRegistryKey &rKey)
|
|
|
|
{
|
|
|
|
HKEY hKey;
|
|
|
|
LONG nError = OpenSubkey(samDesired, pszSubkeyName, hKey);
|
|
|
|
|
|
|
|
if (nError == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
const TCHAR *pszKeyName = GetKeyName();
|
|
|
|
size_t size = _tcslen(pszKeyName) + _tcslen(pszSubkeyName) + 1;
|
|
|
|
TCHAR *pszSubkeyFullName = new TCHAR [size];
|
|
|
|
if (!pszSubkeyFullName)
|
|
|
|
{
|
|
|
|
nError = RegCloseKey(hKey);
|
|
|
|
ASSERT(nError == ERROR_SUCCESS);
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
}
|
|
|
|
_tcscpy(pszSubkeyFullName,pszKeyName);
|
|
|
|
_tcscat(pszSubkeyFullName,pszSubkeyName);
|
|
|
|
HRESULT hr = rKey.Init(hKey,GetKeyName(),pszSubkeyName,samDesired);
|
|
|
|
delete pszSubkeyName;
|
|
|
|
if (FAILED(hr))
|
|
|
|
{
|
|
|
|
nError = RegCloseKey(hKey);
|
|
|
|
ASSERT(nError == ERROR_SUCCESS);
|
|
|
|
if (hr == (HRESULT)E_OUTOFMEMORY)
|
|
|
|
return ERROR_OUTOFMEMORY;
|
|
|
|
else
|
|
|
|
return ERROR_INTERNAL_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nError;
|
|
|
|
}
|
|
|
|
|
|
|
|
LONG CRegistryKey::GetSubkeyNameMaxLength(DWORD &rdwMaxSubkeyNameLength)
|
|
|
|
{
|
|
|
|
if (m_hKey == NULL)
|
|
|
|
{ // root key
|
|
|
|
rdwMaxSubkeyNameLength = 0;
|
|
|
|
for(int i = 0; i < 7 ; i++)
|
|
|
|
{
|
|
|
|
size_t l = _tcslen(g_ppszHiveNames[i]);
|
|
|
|
if (rdwMaxSubkeyNameLength < l)
|
|
|
|
rdwMaxSubkeyNameLength = l;
|
|
|
|
}
|
|
|
|
|
|
|
|
rdwMaxSubkeyNameLength++; // terminating null
|
|
|
|
|
|
|
|
return ERROR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
LONG nRet;
|
|
|
|
|
|
|
|
nRet = RegQueryInfoKey(m_hKey,NULL,NULL,NULL,NULL,&rdwMaxSubkeyNameLength,NULL,NULL,NULL,NULL,NULL,NULL);
|
|
|
|
|
|
|
|
rdwMaxSubkeyNameLength = (nRet == ERROR_SUCCESS)?(rdwMaxSubkeyNameLength+1):0;
|
|
|
|
|
|
|
|
return nRet;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CRegistryKey::InitSubkeyEnumeration(TCHAR *pszSubkeyNameBuffer, DWORD dwBufferSize)
|
|
|
|
{
|
|
|
|
m_pchSubkeyNameBuffer = pszSubkeyNameBuffer;
|
|
|
|
m_dwSubkeyNameBufferSize = dwBufferSize;
|
|
|
|
m_dwCurrentSubKeyIndex = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
LONG CRegistryKey::GetNextSubkeyName(DWORD *pdwActualSize)
|
|
|
|
{
|
|
|
|
LONG nError;
|
|
|
|
|
|
|
|
if (m_hKey == NULL)
|
|
|
|
{
|
|
|
|
if (m_dwCurrentSubKeyIndex < (DWORD)(m_pszMachineName?5:7))
|
|
|
|
{
|
|
|
|
DWORD dwIndex = m_pszMachineName?m_dwCurrentSubKeyIndex+2:m_dwCurrentSubKeyIndex;
|
|
|
|
_tcsncpy(m_pchSubkeyNameBuffer,g_ppszHiveNames[dwIndex],m_dwSubkeyNameBufferSize);
|
|
|
|
nError = ERROR_SUCCESS;
|
|
|
|
if (pdwActualSize)
|
|
|
|
*pdwActualSize = strlen(m_pchSubkeyNameBuffer);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nError = ERROR_NO_MORE_ITEMS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
DWORD dwActualSize = m_dwSubkeyNameBufferSize;
|
|
|
|
FILETIME ft;
|
|
|
|
nError = RegEnumKeyEx(m_hKey,
|
|
|
|
m_dwCurrentSubKeyIndex,
|
|
|
|
m_pchSubkeyNameBuffer,
|
|
|
|
&dwActualSize,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
NULL,
|
|
|
|
&ft);
|
|
|
|
if (pdwActualSize)
|
|
|
|
*pdwActualSize = dwActualSize;
|
|
|
|
}
|
|
|
|
|
2000-10-04 21:04:31 +00:00
|
|
|
m_dwCurrentSubKeyIndex++;
|
|
|
|
|
2001-01-10 01:25:29 +00:00
|
|
|
if (pdwActualSize)
|
|
|
|
*pdwActualSize = strlen(m_pchSubkeyNameBuffer);
|
|
|
|
return nError;
|
2000-10-04 21:04:31 +00:00
|
|
|
}
|
|
|
|
|
2001-01-10 01:25:29 +00:00
|
|
|
LONG CRegistryKey::GetSubkeyCount(DWORD &rdwSubkeyCount)
|
2000-10-04 21:04:31 +00:00
|
|
|
{
|
2001-01-10 01:25:29 +00:00
|
|
|
return RegQueryInfoKeyW(m_hKey,NULL,NULL,NULL,&rdwSubkeyCount,NULL,NULL,NULL,NULL,NULL,NULL,NULL);
|
2000-10-04 21:04:31 +00:00
|
|
|
}
|
|
|
|
|
2001-01-10 01:25:29 +00:00
|
|
|
LONG CRegistryKey::GetMaxValueDataSize(DWORD& rdwMaxValueDataBuferSize)
|
2000-10-04 21:04:31 +00:00
|
|
|
{
|
2001-01-10 01:25:29 +00:00
|
|
|
return RegQueryInfoKeyW(m_hKey,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,&rdwMaxValueDataBuferSize,NULL,NULL);
|
2000-10-04 21:04:31 +00:00
|
|
|
}
|
|
|
|
|
2001-01-10 01:25:29 +00:00
|
|
|
LONG CRegistryKey::GetMaxValueNameLength(DWORD& rdwMaxValueNameBuferSize)
|
2000-10-04 21:04:31 +00:00
|
|
|
{
|
2002-01-04 22:07:38 +00:00
|
|
|
rdwMaxValueNameBuferSize = 0;
|
|
|
|
|
2001-01-10 01:25:29 +00:00
|
|
|
if (!m_hKey)
|
|
|
|
return 0; // the root key abstraction has only subkeys (hives)
|
|
|
|
|
|
|
|
LONG nError = RegQueryInfoKeyW(m_hKey,NULL,NULL,NULL,NULL,NULL,NULL,NULL,&rdwMaxValueNameBuferSize,NULL,NULL,NULL);
|
2000-10-04 21:04:31 +00:00
|
|
|
|
2001-01-10 01:25:29 +00:00
|
|
|
rdwMaxValueNameBuferSize++;
|
|
|
|
return nError;
|
2000-10-04 21:04:31 +00:00
|
|
|
}
|
|
|
|
|
2001-01-10 01:25:29 +00:00
|
|
|
void CRegistryKey::InitValueEnumeration(TCHAR *pszValueNameBuffer,
|
|
|
|
DWORD dwValueNameBufferSize,
|
|
|
|
BYTE *pbValueDataBuffer,
|
|
|
|
DWORD dwValueDataBufferSize,
|
|
|
|
DWORD *pdwType)
|
2000-10-04 21:04:31 +00:00
|
|
|
{
|
2001-01-10 01:25:29 +00:00
|
|
|
m_pszValueNameBuffer = pszValueNameBuffer;
|
|
|
|
m_dwValueNameBufferSize = dwValueNameBufferSize;
|
|
|
|
m_pbValueDataBuffer = pbValueDataBuffer;
|
|
|
|
m_dwValueDataBufferSize = dwValueDataBufferSize;
|
|
|
|
m_pdwType = pdwType;
|
|
|
|
|
|
|
|
m_dwCurrentValueIndex = 0;
|
2000-10-04 21:04:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-01-10 01:25:29 +00:00
|
|
|
// On input dwValueNameSize is size in characters of buffer pointed by pchValueNameBuffer
|
|
|
|
// On output dwValueNameSize contains number of characters stored in buffer
|
|
|
|
LONG CRegistryKey::GetNextValue(DWORD *pdwNameActualSize, DWORD *pdwDataActualSize)
|
|
|
|
{
|
|
|
|
if (!m_hKey)
|
|
|
|
return ERROR_NO_MORE_ITEMS; // the root key abstraction has only subkeys (hives)
|
|
|
|
|
|
|
|
DWORD dwValueNameBufferSize = m_dwValueNameBufferSize;
|
|
|
|
DWORD dwValueDataBufferSize = m_dwValueDataBufferSize;
|
|
|
|
LONG nError = RegEnumValue(m_hKey,
|
|
|
|
m_dwCurrentValueIndex,
|
|
|
|
m_pszValueNameBuffer,
|
|
|
|
&dwValueNameBufferSize,
|
|
|
|
NULL,
|
|
|
|
m_pdwType,
|
|
|
|
m_pbValueDataBuffer,
|
|
|
|
&dwValueDataBufferSize);
|
|
|
|
|
|
|
|
if (pdwNameActualSize)
|
|
|
|
*pdwNameActualSize = dwValueNameBufferSize;
|
|
|
|
|
|
|
|
if (pdwDataActualSize)
|
|
|
|
*pdwDataActualSize = dwValueDataBufferSize;
|
|
|
|
|
|
|
|
m_dwCurrentValueIndex++;
|
|
|
|
return nError;
|
2000-10-04 21:04:31 +00:00
|
|
|
}
|
|
|
|
|
2001-01-10 01:25:29 +00:00
|
|
|
LONG CRegistryKey::GetValueCount(DWORD& rdwValueCount)
|
2000-10-04 21:04:31 +00:00
|
|
|
{
|
2001-01-10 01:25:29 +00:00
|
|
|
if (!m_hKey)
|
|
|
|
return 0; // the root key abstraction has only subkeys (hives)
|
|
|
|
|
|
|
|
return RegQueryInfoKeyW(m_hKey,NULL,NULL,NULL,NULL,NULL,NULL,&rdwValueCount,NULL,NULL,NULL,NULL);
|
2000-10-04 21:04:31 +00:00
|
|
|
}
|
|
|
|
|
2001-01-10 01:25:29 +00:00
|
|
|
LONG CRegistryKey::GetDefaultValue(DWORD *pdwType,
|
|
|
|
BYTE *pbValueDataBuffer,
|
|
|
|
DWORD dwValueDataBufferSize,
|
|
|
|
DWORD *pdwValueDataActualSize)
|
2000-10-04 21:04:31 +00:00
|
|
|
{
|
2001-01-10 01:25:29 +00:00
|
|
|
DWORD dwBufferSize = dwValueDataBufferSize;
|
|
|
|
|
|
|
|
LONG nError = RegQueryValueEx(m_hKey,NULL,NULL,pdwType,pbValueDataBuffer,&dwBufferSize);
|
2000-10-04 21:04:31 +00:00
|
|
|
|
2001-01-10 01:25:29 +00:00
|
|
|
if (pdwValueDataActualSize && (nError == ERROR_SUCCESS))
|
|
|
|
*pdwValueDataActualSize = dwBufferSize;
|
2000-10-04 21:04:31 +00:00
|
|
|
|
2001-01-10 01:25:29 +00:00
|
|
|
return nError;
|
2000-10-04 21:04:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const TCHAR * CRegistryKey::GetValueTypeName(DWORD dwType)
|
|
|
|
{
|
|
|
|
switch(dwType)
|
|
|
|
{
|
|
|
|
case REG_NONE:
|
2001-01-10 01:25:29 +00:00
|
|
|
return _T("REG_NONE");
|
2000-10-04 21:04:31 +00:00
|
|
|
case REG_SZ:
|
2001-01-10 01:25:29 +00:00
|
|
|
return _T("REG_SZ");
|
2000-10-04 21:04:31 +00:00
|
|
|
case REG_EXPAND_SZ:
|
2001-01-10 01:25:29 +00:00
|
|
|
return _T("REG_EXPAND_SZ");
|
2000-10-04 21:04:31 +00:00
|
|
|
case REG_BINARY:
|
2001-01-10 01:25:29 +00:00
|
|
|
return _T("REG_BINARY");
|
2000-10-04 21:04:31 +00:00
|
|
|
case REG_DWORD_LITTLE_ENDIAN:
|
2001-01-10 01:25:29 +00:00
|
|
|
return _T("REG_DWORD_LITTLE_ENDIAN");
|
2000-10-04 21:04:31 +00:00
|
|
|
case REG_DWORD_BIG_ENDIAN:
|
2001-01-10 01:25:29 +00:00
|
|
|
return _T("REG_DWORD_BIG_ENDIAN");
|
2000-10-04 21:04:31 +00:00
|
|
|
case REG_LINK:
|
2001-01-10 01:25:29 +00:00
|
|
|
return _T("REG_LINK");
|
2000-10-04 21:04:31 +00:00
|
|
|
case REG_MULTI_SZ:
|
2001-01-10 01:25:29 +00:00
|
|
|
return _T("REG_MULTI_SZ");
|
2000-10-04 21:04:31 +00:00
|
|
|
case REG_RESOURCE_LIST:
|
2001-01-10 01:25:29 +00:00
|
|
|
return _T("REG_RESOURCE_LIST");
|
2000-10-04 21:04:31 +00:00
|
|
|
case REG_FULL_RESOURCE_DESCRIPTOR:
|
|
|
|
return _T("REG_FULL_RESOURCE_DESCRIPTOR");
|
|
|
|
case REG_RESOURCE_REQUIREMENTS_LIST:
|
|
|
|
return _T("REG_RESOURCE_REQUIREMENTS_LIST");
|
|
|
|
default:
|
2001-01-10 01:25:29 +00:00
|
|
|
return _T("Unkown Type");
|
2000-10-04 21:04:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
DWORD CRegistryKey::GetValue(TCHAR *pchValueName, DWORD *pdwType, LPBYTE lpValueDataBuffer, DWORD *pdwValueDataSize)
|
|
|
|
{
|
|
|
|
return RegQueryValueEx(m_hKey,pchValueName,NULL,pdwType,lpValueDataBuffer,pdwValueDataSize);
|
|
|
|
}
|
|
|
|
|
2001-01-10 01:25:29 +00:00
|
|
|
LONG CRegistryKey::CreateSubkey(REGSAM samDesired,
|
|
|
|
const TCHAR *pszSubkeyName,
|
|
|
|
HKEY &rhKey,
|
|
|
|
BOOL *pblnOpened,
|
|
|
|
BOOL blnVolatile)
|
2000-10-04 21:04:31 +00:00
|
|
|
{
|
2001-01-10 01:25:29 +00:00
|
|
|
DWORD dwDisposition;
|
|
|
|
|
|
|
|
LONG nError = RegCreateKeyEx(
|
|
|
|
m_hKey,
|
|
|
|
pszSubkeyName,
|
|
|
|
0,
|
|
|
|
NULL,
|
|
|
|
blnVolatile?REG_OPTION_VOLATILE:REG_OPTION_NON_VOLATILE,
|
|
|
|
samDesired,
|
|
|
|
NULL,
|
|
|
|
&rhKey,
|
|
|
|
&dwDisposition);
|
2000-10-04 21:04:31 +00:00
|
|
|
|
2001-01-10 01:25:29 +00:00
|
|
|
if ((nError == ERROR_SUCCESS)&&(pblnOpened))
|
|
|
|
*pblnOpened = dwDisposition == REG_OPENED_EXISTING_KEY;
|
|
|
|
|
|
|
|
return nError;
|
2000-10-04 21:04:31 +00:00
|
|
|
}
|
|
|
|
|
2001-01-10 01:25:29 +00:00
|
|
|
LONG CRegistryKey::GetLastWriteTime(SYSTEMTIME &st)
|
2000-10-04 21:04:31 +00:00
|
|
|
{
|
2001-01-10 01:25:29 +00:00
|
|
|
FILETIME ftLocal,ft;
|
|
|
|
LONG nError = RegQueryInfoKeyW(m_hKey,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,&ft);
|
2000-10-04 21:04:31 +00:00
|
|
|
|
2001-01-10 01:25:29 +00:00
|
|
|
if (nError == ERROR_SUCCESS)
|
|
|
|
{
|
|
|
|
FileTimeToLocalFileTime(&ft,&ftLocal);
|
|
|
|
FileTimeToSystemTime(&ftLocal,&st);
|
|
|
|
}
|
|
|
|
|
|
|
|
return nError;
|
2000-10-04 21:04:31 +00:00
|
|
|
}
|
|
|
|
|
2001-01-10 01:25:29 +00:00
|
|
|
const TCHAR * CRegistryKey::GetLastWriteTime()
|
2000-10-04 21:04:31 +00:00
|
|
|
{
|
2001-01-10 01:25:29 +00:00
|
|
|
SYSTEMTIME st;
|
|
|
|
if (GetLastWriteTime(st) != ERROR_SUCCESS)
|
|
|
|
return _T("(Cannot get time last write time)");
|
|
|
|
|
|
|
|
static TCHAR Buffer[256];
|
|
|
|
_stprintf(Buffer,_T("%d.%d.%d %02d:%02d:%02d"),st.wDay,st.wMonth,st.wYear,st.wHour,st.wMinute,st.wSecond);
|
|
|
|
return Buffer;
|
2000-10-04 21:04:31 +00:00
|
|
|
}
|
|
|
|
|
2001-01-10 01:25:29 +00:00
|
|
|
LONG CRegistryKey::GetSecurityDescriptorLength(DWORD *pdwSecurityDescriptor)
|
2000-10-04 21:04:31 +00:00
|
|
|
{
|
2001-01-10 01:25:29 +00:00
|
|
|
return RegQueryInfoKeyW(m_hKey,NULL,NULL,NULL,NULL,NULL,NULL,NULL,
|
|
|
|
NULL,NULL,pdwSecurityDescriptor,NULL);
|
2000-10-04 21:04:31 +00:00
|
|
|
}
|
|
|
|
|
2001-01-10 01:25:29 +00:00
|
|
|
LONG CRegistryKey::GetSecurityDescriptor(SECURITY_INFORMATION SecurityInformation, PSECURITY_DESCRIPTOR pSecurityDescriptor, LPDWORD lpcbSecurityDescriptor)
|
2000-10-04 21:04:31 +00:00
|
|
|
{
|
2001-01-10 01:25:29 +00:00
|
|
|
return RegGetKeySecurity(m_hKey,SecurityInformation,pSecurityDescriptor,lpcbSecurityDescriptor);
|
2000-10-04 21:04:31 +00:00
|
|
|
}
|
|
|
|
|
2001-01-10 01:25:29 +00:00
|
|
|
LONG CRegistryKey::DeleteSubkey(const TCHAR *pszSubkeyName)
|
2000-10-04 21:04:31 +00:00
|
|
|
{
|
2001-01-10 01:25:29 +00:00
|
|
|
return RegDeleteKey(m_hKey,pszSubkeyName);
|
2000-10-04 21:04:31 +00:00
|
|
|
}
|
|
|
|
|
2001-01-10 01:25:29 +00:00
|
|
|
LONG CRegistryKey::SetValue(LPCTSTR pszValueName, DWORD dwType, BYTE *lpData, DWORD dwDataSize)
|
2000-10-04 21:04:31 +00:00
|
|
|
{
|
|
|
|
return RegSetValueEx(m_hKey,pszValueName,0,dwType,lpData,dwDataSize);
|
|
|
|
}
|
2000-10-24 20:17:42 +00:00
|
|
|
|
2001-01-10 01:25:29 +00:00
|
|
|
LONG CRegistryKey::DeleteValue(const TCHAR *pszValueName)
|
2000-10-24 20:17:42 +00:00
|
|
|
{
|
|
|
|
return RegDeleteValue(m_hKey,pszValueName);
|
|
|
|
}
|