在编码时总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