本文整理汇总了C++中RegQueryInfoKey函数的典型用法代码示例。如果您正苦于以下问题:C++ RegQueryInfoKey函数的具体用法?C++ RegQueryInfoKey怎么用?C++ RegQueryInfoKey使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RegQueryInfoKey函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: TEXT
long RegistryRW::GetInfoKey(const HKEY& key ,DWORD & numItems,DWORD & biggestValueSize) const
{
long ret;
TCHAR achClass[MAX_PATH] = TEXT(""); // buffer for class name
DWORD cchClassName = MAX_PATH; // size of class string
DWORD cValues; // number of values for key
DWORD maxValueSize; // size of security descriptor
ret = RegQueryInfoKey(
key, // key handle
achClass, // buffer for class name
&cchClassName, // size of class string
NULL, // reserved
NULL, // number of subkeys
NULL, // longest subkey size
NULL, // longest class string
&cValues, // number of values for this key
NULL, // longest value name
&maxValueSize, // longest value data
NULL, // security descriptor
NULL);
numItems = cValues;
biggestValueSize = maxValueSize;
return ret;
}
示例2: EnumPath_local
//------------------------------------------------------------------------------
void EnumPath_local(HKEY hk,char *chk, char*key_before,char *key_after,unsigned int session_id, sqlite3 *db)
{
HKEY CleTmp;
if (RegOpenKey(hk,key_before,&CleTmp)!=ERROR_SUCCESS)return;
DWORD nbSubKey=0,i;
if (RegQueryInfoKey (CleTmp,NULL,NULL,NULL,&nbSubKey,NULL,NULL,NULL,NULL,NULL,NULL,NULL)!=ERROR_SUCCESS)
{
RegCloseKey(CleTmp);
return;
}
char key[MAX_PATH], tmp_key[MAX_PATH];
DWORD key_size;
for (i=0;i<nbSubKey && start_scan;i++)
{
key[0] = 0;
key_size = MAX_PATH;
if (RegEnumKeyEx (CleTmp,i,key,(LPDWORD)&key_size,NULL,NULL,NULL,NULL)==ERROR_SUCCESS)
{
if (key_after!=NULL)snprintf(tmp_key,MAX_PATH,"%s\\%s\\%s",key_before,key,key_after);
else snprintf(tmp_key,MAX_PATH,"%s\\%s",key_before,key);
reg_read_enum_PathValues(hk,chk,tmp_key,session_id,db);
}
}
RegCloseKey(CleTmp);
}
示例3: FindProvRegVals
static BOOL FindProvRegVals(DWORD dwIndex, DWORD *pdwProvType, LPSTR *pszProvName,
DWORD *pcbProvName, DWORD *pdwProvCount)
{
HKEY hKey;
HKEY subkey;
DWORD size = sizeof(DWORD);
if (RegOpenKey(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Cryptography\\Defaults\\Provider", &hKey))
return FALSE;
RegQueryInfoKey(hKey, NULL, NULL, NULL, pdwProvCount, pcbProvName,
NULL, NULL, NULL, NULL, NULL, NULL);
(*pcbProvName)++;
if (!(*pszProvName = LocalAlloc(LMEM_ZEROINIT, *pcbProvName)))
return FALSE;
RegEnumKeyEx(hKey, dwIndex, *pszProvName, pcbProvName, NULL, NULL, NULL, NULL);
(*pcbProvName)++;
RegOpenKey(hKey, *pszProvName, &subkey);
RegQueryValueEx(subkey, "Type", NULL, NULL, (LPBYTE)pdwProvType, &size);
RegCloseKey(subkey);
RegCloseKey(hKey);
return TRUE;
}
示例4: RegCreateKeyEx
bool RegKey::open(HKEY hKey, tstring lpSubKey,REGSAM samDesired,bool createIfNotExists)
{
if(m_hKeyHandle != NULL) close();
LONG lResult;
m_pAccess = samDesired;
if(createIfNotExists)
lResult = RegCreateKeyEx(hKey,lpSubKey.c_str(),0,NULL,REG_OPTION_NON_VOLATILE, samDesired, NULL, &m_hKeyHandle, &m_dwDisposition);
else {
m_dwDisposition = REG_OPENED_EXISTING_KEY;
lResult = RegOpenKeyEx(hKey, lpSubKey.c_str(), 0, samDesired, &m_hKeyHandle);
}
if(lResult != ERROR_SUCCESS) return false;
lResult = RegQueryInfoKey(
m_hKeyHandle, // key handle
REGKEYINFO.achClass, // buffer for class name
®KEYINFO.cchClassName, // size of class string
NULL, // reserved
®KEYINFO.cSubKeys, // number of subkeys
®KEYINFO.cbMaxSubKey, // longest subkey size
®KEYINFO.cchMaxClass, // longest class string
®KEYINFO.cValues, // number of values for this key
®KEYINFO.cchMaxValue, // longest value name
®KEYINFO.cbMaxValueData, // longest value data
®KEYINFO.cbSecurityDescriptor, // security descriptor
®KEYINFO.ftLastWriteTime); // last write time
return true;
}
示例5: RegOpenKeyEx
int DeviceManagementNode::getChildrenMaxCount() {
HKEY key;
ULONG howMany = 0;
RegOpenKeyEx(
HKEY_DM_ROOT,
fullContext,
0,
KEY_READ,
&key
);
if (key == 0) {
//lastErrorCode = ERR_INVALID_CONTEXT;
//sprintf(lastErrorMsg, "Invalid context path: %s", fullContext);
setErrorF(ERR_INVALID_CONTEXT, "Invalid context path: %s", fullContext);
goto finally;
}
RegQueryInfoKey(
key, NULL, NULL, NULL, &howMany, NULL, NULL, NULL, NULL, NULL, NULL, NULL
);
finally:
if (key != 0) {
RegCloseKey(key);
}
return howMany;
}
示例6: SaveToRegistry
bool CTestResource::SaveToRegistry(HKEY key,LPCTSTR psz)
{
bool rc=false;
ENTERCRITICAL;
// Delete all the keys under "psz"
HKEY hKey;
if(ERROR_SUCCESS==RegOpenKeyEx ((HKEY)key, psz, 0L, KEY_ENUMERATE_SUB_KEYS, &hKey)){
TCHAR szName[256];
DWORD dwSizeName=sizeof szName;
FILETIME ftLastWriteTime;
DWORD dwIndex;
if(ERROR_SUCCESS==RegQueryInfoKey(hKey,0,0,0,&dwIndex,0,0,0,0,0,0,0)){
while((signed)--dwIndex>=0){
if(ERROR_SUCCESS!=RegEnumKeyEx(hKey, dwIndex, szName, &dwSizeName, NULL, NULL, NULL, &ftLastWriteTime) ||
ERROR_SUCCESS!=RegDeleteKey(hKey,szName)){
rc=false;
}
dwSizeName=sizeof szName;
}
}
RegCloseKey(hKey);
}
rc=true;
for(CTestResource *pResource=pFirstInstance;pResource;pResource=pResource->m_pNextInstance){
CTestResourceProperties prop1(pResource);
rc&=prop1.SaveToRegistry(key,pResource->FileName());
}
LEAVECRITICAL;
return rc;
}
示例7: getAllKeys
std::list<std::wstring> getAllKeys()
{
std::list<std::wstring> result;
HKEY hKey;
RegOpenKeyEx(HKEY_LOCAL_MACHINE, TEXT("SYSTEM\\CurrentControlSet\\Enum\\DISPLAY"), 0, KEY_READ, &hKey);
TCHAR achKey[MAX_KEY_LENGTH]; // buffer for subkey name
DWORD cbName; // size of name string
TCHAR achClass[MAX_PATH] = TEXT(""); // buffer for class name
DWORD cchClassName = MAX_PATH; // size of class string
DWORD cSubKeys=0; // number of subkeys
DWORD cbMaxSubKey; // longest subkey size
DWORD cchMaxClass; // longest class string
DWORD cValues; // number of values for key
DWORD cchMaxValue; // longest value name
DWORD cbMaxValueData; // longest value data
DWORD cbSecurityDescriptor; // size of security descriptor
FILETIME ftLastWriteTime; // last write time
DWORD i, retCode;
// Get the class name and the value count.
retCode = RegQueryInfoKey(
hKey, // key handle
achClass, // buffer for class name
&cchClassName, // size of class string
NULL, // reserved
&cSubKeys, // number of subkeys
&cbMaxSubKey, // longest subkey size
&cchMaxClass, // longest class string
&cValues, // number of values for this key
&cchMaxValue, // longest value name
&cbMaxValueData, // longest value data
&cbSecurityDescriptor, // security descriptor
&ftLastWriteTime); // last write time
// Enumerate the subkeys, until RegEnumKeyEx fails.
if (cSubKeys)
{
//std::cout << "Number of subkeys: " << cSubKeys <<std::endl;
for (i=0; i<cSubKeys; i++)
{
cbName = MAX_KEY_LENGTH;
retCode = RegEnumKeyEx(hKey, i,
achKey,
&cbName,
NULL,
NULL,
NULL,
&ftLastWriteTime);
if (retCode == ERROR_SUCCESS)
result.push_back(achKey);
}
}
RegCloseKey(hKey);
return result;
}
示例8: EnumerateSubKeys
void EnumerateSubKeys(HKEY RootKey, char* subKey, unsigned int tabs = 0)
{
HKEY hKey;
DWORD cSubKeys; //Used to store the number of Subkeys
DWORD maxSubkeyLen; //Longest Subkey name length
DWORD cValues; //Used to store the number of Subkeys
DWORD maxValueLen; //Longest Subkey name length
DWORD retCode; //Return values of calls
RegOpenKeyEx(RootKey, subKey, 0, KEY_ALL_ACCESS, &hKey);
RegQueryInfoKey(hKey, // key handle
NULL, // buffer for class name
NULL, // size of class string
NULL, // reserved
&cSubKeys, // number of subkeys
&maxSubkeyLen, // longest subkey length
NULL, // longest class string
&cValues, // number of values for this key
&maxValueLen, // longest value name
NULL, // longest value data
NULL, // security descriptor
NULL); // last write time
if(cSubKeys>0)
{
char currentSubkey[MAX_PATH];
for(int i=0;i < cSubKeys;i++){
DWORD currentSubLen=MAX_PATH;
retCode=RegEnumKeyEx(hKey, // Handle to an open/predefined key
i, // Index of the subkey to retrieve.
currentSubkey, // buffer to receives the name of the subkey
¤tSubLen, // size of that buffer
NULL, // Reserved
NULL, // buffer for class string
NULL, // size of that buffer
NULL); // last write time
if(retCode==ERROR_SUCCESS)
{
for (int i = 0; i < tabs; i++)
printf("\t");
printf("(%d) %s\n", i+1, currentSubkey);
char* subKeyPath = new char[currentSubLen + strlen(subKey)];
sprintf(subKeyPath, "%s\\%s", subKey, currentSubkey);
EnumerateSubKeys(RootKey, subKeyPath, (tabs + 1));
}
}
}
else
{
EnumerateValues(hKey, cValues);
}
RegCloseKey(hKey);
}
示例9: RegDeleteSubKeys
/* delete all subkeys in the given key */
bool
RegDeleteSubKeys (HKEY hKey)
{
DWORD dwSubKeyCnt, dwMaxSubKey;
if (RegQueryInfoKey (hKey, NULL, NULL, 0, &dwSubKeyCnt, &dwMaxSubKey,
NULL, NULL, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
{
if (dwSubKeyCnt)
{
LPTSTR pszKeyName = (LPTSTR) malloc (dwMaxSubKey += 1);
if (pszKeyName)
{
do
{
if (RegEnumKey (hKey, --dwSubKeyCnt, pszKeyName, dwMaxSubKey) == ERROR_SUCCESS)
{
HKEY hSubKey = RegOpen (hKey, pszKeyName, KEY_READ | KEY_WRITE);
if (hSubKey)
{
if (RegDeleteSubKeys (hSubKey))
{
RegClose (hSubKey);
if (RegDeleteKey (hKey, pszKeyName) != ERROR_SUCCESS)
{
free (pszKeyName);
return false;
}
}
else
{
RegClose (hSubKey);
free (pszKeyName);
return false;
}
}
else
{
free (pszKeyName);
return false;
}
}
else
{
free (pszKeyName);
return false;
}
}
while (dwSubKeyCnt);
free (pszKeyName);
}
else
{
return false;
}
}
return true;
}
return false;
}
示例10: GetRegistryChanges
void GetRegistryChanges(HKEY hKey)
{
TCHAR szKey[MAX_KEY_LENGTH];
DWORD cbName;
DWORD cSubKeys=0;
FILETIME ftWrite;
DWORD i, ret;
HKEY hNewKey;
ULARGE_INTEGER tmWrite;
TCHAR szName[MAX_KEY_LENGTH];
// get the number of subkeys
ret = RegQueryInfoKey( // WinReg.h
hKey,
NULL, NULL, NULL,
&cSubKeys,
NULL, NULL, NULL, NULL,
NULL, NULL, NULL);
// for each subkey, see if it changed based on its
// last write timestamp
for (i=0; i<cSubKeys; i++)
{
cbName = MAX_KEY_LENGTH;
ret = RegEnumKeyEx( // WinReg.h
hKey, i, szKey, &cbName,
NULL, NULL, NULL, &ftWrite);
if (ret == ERROR_SUCCESS)
{
tmWrite.HighPart = ftWrite.dwHighDateTime;
tmWrite.LowPart = ftWrite.dwLowDateTime;
// it changed if the last write is greater than
// our start time
if (tmWrite.QuadPart > g_tmStart.QuadPart)
{
memset(szName, 0, sizeof(szName));
GetKeyName(hKey, szName);
_tcscat(szName, _T("\\")); // 문자열 추가 strcat_s
_tcscat(szName, szKey);
if (!IsWhitelisted(szName)) {
Output(FOREGROUND_BLUE, _T("[REGISTRY] %s\n"), szName);
}
}
ret = RegOpenKeyEx(hKey, szKey, 0, KEY_READ, &hNewKey);
if (ret == ERROR_SUCCESS)
{
GetRegistryChanges(hNewKey);
RegCloseKey(hNewKey);
}
}
}
}
示例11: fix_value_result
static BOOL
fix_value_result(RegPort* rp, LONG result, DWORD type,
LPSTR name, DWORD nameSize, LPSTR value, DWORD valueSize)
{
if (result == ERROR_MORE_DATA) {
DWORD max_name1;
DWORD max_name2;
DWORD max_value;
int ok;
ok = RegQueryInfoKey(rp->hkey, NULL, NULL, NULL,
NULL, &max_name1, NULL, NULL, &max_name2,
&max_value, NULL, NULL);
#ifdef DEBUG
if (ok != ERROR_SUCCESS) {
char buff[256];
sprintf(buff,"Failure in registry_drv line %d, error = %d",
__LINE__, GetLastError());
MessageBox(NULL, buff, "Internal error", MB_OK);
ASSERT(ok == ERROR_SUCCESS);
}
#endif
rp->name_buf_size = (max_name1 > max_name2 ? max_name1 : max_name2)
+ 1;
rp->value_buf_size = max_value + 1;
rp->name_buf = driver_realloc(rp->name_buf, rp->name_buf_size);
rp->value_buf = driver_realloc(rp->value_buf, rp->value_buf_size);
return FALSE;
} else if (result != ERROR_SUCCESS) {
reply(rp, result);
return TRUE;
}
/*
* Do some data conversion which is easier to do here
* than in Erlang.
*/
switch (type) {
case REG_SZ:
case REG_EXPAND_SZ:
valueSize--; /* No reason to send the '\0' to Erlang. */
break;
case REG_DWORD_LITTLE_ENDIAN:
case REG_DWORD_BIG_ENDIAN:
/*
* The value is a DWORD stored in host byte order.
* We must retrieve it and store it in network byte order.
*/
{
DWORD dword = * ((DWORD *) value);
put_int32(dword, value);
type = REG_DWORD; /* Simplify life for Erlang code. */
break;
}
}
return value_reply(rp, type, name, nameSize, value, valueSize);
}
示例12: FindProvTypesRegVals
static BOOL FindProvTypesRegVals(DWORD *pdwIndex, DWORD *pdwProvType, LPSTR *pszTypeName,
DWORD *pcbTypeName, DWORD *pdwTypeCount)
{
HKEY hKey;
HKEY hSubKey;
PSTR ch;
LPSTR szName;
DWORD cbName;
BOOL ret = FALSE;
if (RegOpenKey(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Cryptography\\Defaults\\Provider Types", &hKey))
return FALSE;
if (RegQueryInfoKey(hKey, NULL, NULL, NULL, pdwTypeCount, &cbName, NULL,
NULL, NULL, NULL, NULL, NULL))
goto cleanup;
cbName++;
if (!(szName = LocalAlloc(LMEM_ZEROINIT, cbName)))
goto cleanup;
while (!RegEnumKeyEx(hKey, *pdwIndex, szName, &cbName, NULL, NULL, NULL, NULL))
{
cbName++;
ch = szName + strlen(szName);
/* Convert "Type 000" to 0, etc/ */
*pdwProvType = *(--ch) - '0';
*pdwProvType += (*(--ch) - '0') * 10;
*pdwProvType += (*(--ch) - '0') * 100;
if (RegOpenKey(hKey, szName, &hSubKey))
break;
if (!RegQueryValueEx(hSubKey, "TypeName", NULL, NULL, NULL, pcbTypeName))
{
if (!(*pszTypeName = LocalAlloc(LMEM_ZEROINIT, *pcbTypeName)))
break;
if (!RegQueryValueEx(hSubKey, "TypeName", NULL, NULL, (LPBYTE)*pszTypeName, pcbTypeName))
{
ret = TRUE;
break;
}
LocalFree(*pszTypeName);
}
RegCloseKey(hSubKey);
(*pdwIndex)++;
}
RegCloseKey(hSubKey);
LocalFree(szName);
cleanup:
RegCloseKey(hKey);
return ret;
}
示例13: ClearStruct
bool TRegistry::GetKeyInfo(TRegKeyInfo & Value) const
{
ClearStruct(Value);
bool Result = RegQueryInfoKey(GetCurrentKey(), nullptr, nullptr, nullptr, &Value.NumSubKeys,
&Value.MaxSubKeyLen, nullptr, &Value.NumValues, &Value.MaxValueLen,
&Value.MaxDataLen, nullptr, &Value.FileTime) == ERROR_SUCCESS;
return Result;
}
示例14: get_child_count
static void get_child_count(HKEY key, DWORD* count, DWORD* largest_subkey)
{
if(RegQueryInfoKey(key, NULL, NULL, NULL, count, largest_subkey, NULL, NULL,
NULL, NULL, NULL, NULL) != ERROR_SUCCESS)
{
*count = 0;
*largest_subkey = 0;
}
}
示例15: childKeysOrGroups
static QStringList childKeysOrGroups(HKEY parentHandle, QSettingsPrivate::ChildSpec spec)
{
QStringList result;
DWORD numKeys;
DWORD maxKeySize;
DWORD numSubgroups;
DWORD maxSubgroupSize;
// Find the number of keys and subgroups, as well as the max of their lengths.
LONG res = RegQueryInfoKey(parentHandle, 0, 0, 0, &numSubgroups, &maxSubgroupSize, 0,
&numKeys, &maxKeySize, 0, 0, 0);
if (res != ERROR_SUCCESS) {
qWarning("QSettings: RegQueryInfoKey() failed: %s", errorCodeToString(res).toLatin1().data());
return result;
}
++maxSubgroupSize;
++maxKeySize;
int n;
int m;
if (spec == QSettingsPrivate::ChildKeys) {
n = numKeys;
m = maxKeySize;
} else {
n = numSubgroups;
m = maxSubgroupSize;
}
/* The size does not include the terminating null character. */
++m;
// Get the list
QByteArray buff(m * sizeof(wchar_t), 0);
for (int i = 0; i < n; ++i) {
QString item;
DWORD l = buff.size() / sizeof(wchar_t);
if (spec == QSettingsPrivate::ChildKeys) {
res = RegEnumValue(parentHandle, i, reinterpret_cast<wchar_t *>(buff.data()), &l, 0, 0, 0, 0);
} else {
res = RegEnumKeyEx(parentHandle, i, reinterpret_cast<wchar_t *>(buff.data()), &l, 0, 0, 0, 0);
}
if (res == ERROR_SUCCESS)
item = QString::fromWCharArray((const wchar_t *)buff.constData(), l);
if (res != ERROR_SUCCESS) {
qWarning("QSettings: RegEnumValue failed: %s", errorCodeToString(res).toLatin1().data());
continue;
}
if (item.isEmpty())
item = QLatin1String(".");
result.append(item);
}
return result;
}