我正在使用 Windows API ( 和 ) 中的一些注册表函数RegOpenKeyEx
假设RegQueryInfoKey
这RegEnumValue
是我到目前为止的代码:
const int MAX_VALUE_NAME= 16383;
const int MAX_DATA = 16383;
DWORD i;
HKEY hKey = HKEY_CURRENT_USER;
LPCTSTR lpSubKey = TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\RunMRU");
DWORD ulOptions = 0;
REGSAM samDesired = KEY_READ | KEY_WRITE | KEY_QUERY_VALUE;
HKEY phkResult;
DWORD dwIndex = 0;
TCHAR lpValueName[MAX_VALUE_NAME];
LPCTSTR ValueMRU;
BYTE *DataMRU;
DWORD lpcchValueName = MAX_VALUE_NAME;
BYTE lpData[MAX_DATA+2];
DWORD cbData = sizeof(lpData);
DWORD type;
TCHAR lpClass[MAX_PATH] = TEXT("");
DWORD lpcClass = MAX_PATH;
LPDWORD lpReserved = NULL;
DWORD lpcSubKeys = 0;
DWORD lpcMaxSubKeyLen;
DWORD lpcMaxClassLen;
DWORD lpcValues;
DWORD lpcMaxValueNameLen;
DWORD lpcMaxValueLen;
DWORD lpcbSecurityDescriptor;
FILETIME lpfLastWriteTime;
char *pMsg = NULL;
long R;
long OpenK = RegOpenKeyEx(hKey, lpSubKey, ulOptions, samDesired, &phkResult);
if (OpenK == ERROR_SUCCESS)
{
long Query = RegQueryInfoKey(phkResult, lpClass, &lpcClass, lpReserved, &lpcSubKeys, &lpcMaxSubKeyLen,
&lpcMaxClassLen, &lpcValues, &lpcMaxValueLen, &lpcMaxValueLen, &lpcbSecurityDescriptor, &lpfLastWriteTime);
if (Query == ERROR_SUCCESS)
{
if (lpcValues)
{
cout << "Number of values in the subkey: " << lpcValues << endl;
cout << "\nThe values are:: \n" << endl;
//Show RunMRU values and content.
for (i = 0; i < lpcValues; i++)
{
lpcchValueName = MAX_VALUE_NAME;
//lpValueName[0] = '\0';
lpValueName[MAX_VALUE_NAME];
//lpData[MAX_DATA + 2];
cbData = MAX_DATA;
R = RegEnumValue(phkResult, i, lpValueName, &lpcchValueName, NULL,
&type, lpData, &cbData);
int Quantity = strlen((const char *)lpData);
if (R != ERROR_NO_MORE_ITEMS)
{
cout << "\0" << lpValueName << ": " << lpData << endl;
cout << "Number of characters: " << Quantity << endl;
cout << "\n";
}
else
{
cout << "Error enumerating values. Code: " << R << endl;
}
}
} //EOIF.
这就是我得到的:
问题是:
- 如何从 lpData 中删除字符串末尾的“\1”?[已解决:见下文]
PD。lpData 获取值的内容,而不是值。
- 如何在不影响“for”以及其他值和内容的情况下避免显示 RunMRU 值?
编辑1:我可以通过将其添加到以下内容来解决“\ 1”问题FOR
:
int Quantity = strlen(lpData);
std::string original = lpData;
std::string result = original.substr(0, original.size() - 2);
std::string result = original.substr(0, Quantity - 2);
if (R != ERROR_NO_MORE_ITEMS)
{
cout << "\0" << lpValueName << ": " << (TCHAR*)result.c_str() << endl;
cout << "Numbers of characters: " << Quantity-2 << endl;
cout << "\n";
}
else
{
cout << "Error enumerating the values. Code: " << R << endl;
}
现在我只需要知道如何避免在 FOR 中显示 MRUList 值。