我无法重定向到regedit中的特定位置 [英] i cannot redirect to particular location in regedit
本文介绍了我无法重定向到regedit中的特定位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面是我的代码:
below is my code:
// letsc.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
//#include <winreg.h>
#include<Windows.h>
#include<string>
bool function();
int _tmain(int argc, _TCHAR* argv[])
{
if (function())
{
//hello
}
getchar;
return 0;
/*HKEY hTestKey;
if (RegOpenKeyEx(HKEY_CURRENT_USER, dom, 0, KEY_READ, &hTestKey) == ERROR_SUCCESS)
{
QueryKey(hTestKey, pre);
prefix[i] = pre[0];
}
RegCloseKey(hTestKey);
return 0;*/
}
bool function()
{
HKEY hKey;
LPCTSTR subKey;
LPCTSTR subValue;
HKEY resKey;
DWORD dataLen;
hKey = HKEY_LOCAL_MACHINE;
subKey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\WindowsUpdate";
//HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\WindowsUpdate\\Auto Update\\RebootRequired"
long key = RegOpenKeyExA(hKey, subKey, 0, KEY_READ | KEY_WRITE, &resKey);
if (key == ERROR_SUCCESS)
{
printf("sucess");
/*subValue = "ProgramData";
long key = RegQueryValueExA(resKey, subValue, NULL, NULL, NULL, NULL);
if (key == ERROR_FILE_NOT_FOUND)
{
return false;
}
else
{
std::string data = "C:\\WINDOWS\\system32\\program.exe";
DWORD dataLen = data.size() + 1;
long key = RegSetValueExA(resKey, subValue, 0, REG_SZ, (const BYTE*)data.c_str(), dataLen);
if (key == ERROR_SUCCESS)
{
return true;
}
else
{
return false;
}
}*/
}
else
{
printf("registry not present");
return false;
}
}
使用上面的代码,当我尝试检查注册表中的密钥时,它显示注册表不存在,因为它存在于那里。我必须做什么
例如Windows更新存在于regedit中,但它显示未找到注册表。
using above code when i try to check key in registry it shows registry not present where as it is present there. what must i do
for example windows update is present in regedit but it is showing registry not found.
推荐答案
可能您的应用程序没有打开HKEY_LOCAL_MACHINE
子树所需的权限。无论如何,您必须根据检查返回值代码。文档 [ ^ ]:
Probably your application has not the right privileges needed to open aHKEY_LOCAL_MACHINE
subtree. Anyway you have to check the return value code, as per the documentation[^] :
如果函数失败,返回值是Winerror.h中定义的非零错误代码。您可以将FormatMessage函数与FORMAT_MESSAGE_FROM_SYSTEM标志一起使用,以获取错误的一般描述。
If the function fails, the return value is a nonzero error code defined in Winerror.h. You can use the FormatMessage function with the FORMAT_MESSAGE_FROM_SYSTEM flag to get a generic description of the error.
这篇关于我无法重定向到regedit中的特定位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文