DWORD dwIndex=0,lpcbname=100,ret=0;
unsigned char * pch = new BYTE[100];
TCHAR T_name[100];
FILETIME lpftlast;
DWORD type_1 = REG_SZ;
int i=0;
CString str, pWnd;
HKEY hRegKey, hRegChildKey;
BOOL bResult;
str=_T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall");
if(RegOpenKey(HKEY_LOCAL_MACHINE, str, &hRegKey) == ERROR_SUCCESS)
{
for(i=0;ret==ERROR_SUCCESS;i++,dwIndex++)
{
ZeroMemory(T_name,100);
lpcbname=100;
ret=RegEnumKeyEx(hRegKey,dwIndex,T_name,&lpcbname,NULL,NULL,NULL,&lpftlast);
if (ret==ERROR_SUCCESS)
{
ZeroMemory(T_name,100);
lpcbname=100;
//下面怎么使用?我用的好像不对啊!
if (RegQueryValueEx(hRegChildKey,L"DisplayName",NULL, &type_1,pch,&lpcbname)==ERROR_SUCCESS)
{
// if (_tcsstr(pch, L"迅雷5")!=NULL)
pWnd.Format(L"%s", pch);
}
}
}
}
unsigned char * pch = new BYTE[100];
TCHAR T_name[100];
FILETIME lpftlast;
DWORD type_1 = REG_SZ;
int i=0;
CString str, pWnd;
HKEY hRegKey, hRegChildKey;
BOOL bResult;
str=_T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall");
if(RegOpenKey(HKEY_LOCAL_MACHINE, str, &hRegKey) == ERROR_SUCCESS)
{
for(i=0;ret==ERROR_SUCCESS;i++,dwIndex++)
{
ZeroMemory(T_name,100);
lpcbname=100;
ret=RegEnumKeyEx(hRegKey,dwIndex,T_name,&lpcbname,NULL,NULL,NULL,&lpftlast);
if (ret==ERROR_SUCCESS)
{
ZeroMemory(T_name,100);
lpcbname=100;
//下面怎么使用?我用的好像不对啊!
if (RegQueryValueEx(hRegChildKey,L"DisplayName",NULL, &type_1,pch,&lpcbname)==ERROR_SUCCESS)
{
// if (_tcsstr(pch, L"迅雷5")!=NULL)
pWnd.Format(L"%s", pch);
}
}
}
}
#include <stdio.h>
#include <tchar.h>#define MAX_KEY_LENGTH 255
#define MAX_VALUE_NAME 16383
void QueryKey(HKEY 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;
TCHAR achValue[MAX_VALUE_NAME];
DWORD cchValue = MAX_VALUE_NAME;
// 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)
{
printf( "\nNumber of subkeys: %d\n", cSubKeys); for (i=0; i<cSubKeys; i++)
{
cbName = MAX_KEY_LENGTH;
retCode = RegEnumKeyEx(hKey, i,
achKey,
&cbName,
NULL,
NULL,
NULL,
&ftLastWriteTime);
if (retCode == ERROR_SUCCESS)
{
_tprintf(TEXT("(%d) %s\n"), i+1, achKey);
}
}
}
// Enumerate the key values. if (cValues)
{
printf( "\nNumber of values: %d\n", cValues); for (i=0, retCode=ERROR_SUCCESS; i<cValues; i++)
{
cchValue = MAX_VALUE_NAME;
achValue[0] = '\0';
retCode = RegEnumValue(hKey, i,
achValue,
&cchValue,
NULL,
NULL,
NULL,
NULL);
if (retCode == ERROR_SUCCESS )
{
_tprintf(TEXT("(%d) %s\n"), i+1, achValue);
}
}
}
}void _tmain(void)
{
HKEY hTestKey; if( RegOpenKeyEx( HKEY_CURRENT_USER,
TEXT("SOFTWARE\\Microsoft"),
0,
KEY_READ,
&hTestKey) == ERROR_SUCCESS
)
{
QueryKey(hTestKey);
}
}
先RegOpenKey再RegQueryValueEx就可以了,不用RegEnumKeyEx.
顺便问一下你们在msdn上怎么找的例子!我怎么找不到啊·!
http://msdn.microsoft.com/我一般用这个!