在編碼時總noob,任何建議表示讚賞。RegQueryValueEx,需要一些幫助
這就是我要做的:
1)在HKLM
2打開運行鍵)讀取REG_SZ我做了所謂的「測試」。
3)閱讀發現然後刪除鍵 「測試」
4)如果 「這個數據」 的數據。
5)關閉密鑰。
我在做什麼錯?
#include <iostream>
#include <Windows.h>
using namespace std;
int main() {
char value[1024];
DWORD value_length = 1024;
DWORD keytype = REG_SZ;
HKEY hk;
LONG result;
LONG result2;
char response;
cout << "Would you like to scan? (Y) or (N)";
cin >> response;
if (response == 'Y')
{
result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion\\Run", 0, KEY_ALL_ACCESS | KEY_WOW64_64KEY, &hk);
if (result == ERROR_SUCCESS) {
result2 = RegQueryValueEx(hk, ("Test"), NULL, &keytype, (LPBYTE)&value, &value_length);
if (result2 == ERROR_ACCESS_DENIED) {
cout << "Access Denied." << endl;
RegCloseKey(hk);
system("pause");
}
else if (result2 == ERROR_MORE_DATA) {
cout << "lpData buffer is too small to receive the data." << endl;
RegCloseKey(hk);
system("pause");
}
else if (result2 == ERROR_FILE_NOT_FOUND) {
cout << "Value does not exist for LpValueName." << endl;
RegCloseKey(hk);
system("pause");
}
else if (result2 == ERROR_SUCCESS) { //If the function succeeds, the return value is ERROR_SUCCESS.
cout << "The value read from the registry is: " << value << endl;
RegCloseKey(hk);
system("pause");
}
}
else if (result == ERROR_FILE_NOT_FOUND)
{
cout << "Key not found." << endl;
system("pause");
}
}
else if (response == 'N')
{
return 0;
system("pause");
}
}
你試過'cout << value <<'\ n';看看它打印了什麼嗎? – Joel
究竟是什麼問題?你已經知道如何讀取數據,你已經在做。數據在你的'value []'數組中。 'RegQueryValueEx()'(你忽略的)的返回值會告訴你該值是否存在於打開的鍵中,'value_length'將告訴你有多少字節被讀取。那麼你只需要根據你的需要掃描'value []'的內容,比如'strncmp()','strstr()'等等。如果找到匹配項,請調用RegDeleteValue()。 –
在一個不相關的說明中,'ERROR_SUCCESS'是一個誤導性的名字! – CinCout