使用VC ++访问注册表键路径 [英] accessing registry key path using VC++
问题描述
嗨大家从以下代码我试图找出是否存在该注册表路径,它成功地给了我一个输出。但是我在这段代码中注意到的是,由于64位操作系统,它默认只检查wow6432Node。现在我想要做的是我想提出一个特定的条件来检查它的路径,即它检查
SOFTWARE \\ Microsoft \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \\\Windows®更新\\Auto Update \\Power以及此
SOFTWARE \\wow6432Node \\ Microsoft \\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \\ WindowsUpdate \\Auto Update \\Power
Hi guys from the following code i try to find out whether that registry path exists or not and it successfully gives me an output. but the thing that i noticed in this code is it checks only wow6432Node by default due to 64 bit OS. now what i want to do is i want to put a specific condition through which it checks both the path i.e it checks
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\WindowsUpdate\\Auto Update\\Power" as well as this
"SOFTWARE\\wow6432Node\\Microsoft\\Windows\\CurrentVersion\\WindowsUpdate\\Auto Update\\Power"
// 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;
}
bool function()
{
HKEY hKey;
LPCTSTR subKey;
LPCTSTR subValue;
HKEY resKey;
DWORD dataLen;
hKey = HKEY_LOCAL_MACHINE;
//subKey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Component Based Servicing\\Version";
subKey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\WindowsUpdate\\Auto Update\\Power";
//subKey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Component Based Servicing\\Version";
//HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\WindowsUpdate\\Auto Update\\RebootRequired"
long key = RegOpenKeyExA(hKey, subKey, 10, KEY_READ | 0 , &resKey);
if (key == ERROR_SUCCESS)
{
printf("Power folder exists");
/*subValue = "Power";
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("power folder doesnot exists");
return false;
}
}
注意上面的代码虽然我给了一个路径为SOFTWARE \\ Microsoft \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\只有
从此我必须做什么才能同时访问这两条路径?
Note in above code though i have given a path as "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\WindowsUpdate\\Auto Update\\Power"
but still it checks wow registry only
henceforth what must i do to get access to both path simultaneously?
推荐答案
hi,
一般意图是只在其中一个路径下创建注册表项。因此,如果用户安装了64位版本,那么我无法猜测为什么应用程序也会在wow6432Node节点下创建注册表项。 (可能是注册表重定向或其他东西)
检查确定系统是64位还是32位就足以应对这种情况,然后相应地检查密钥。
查看Raymond Chen的建议 [< a href =http://blogs.msdn.com/b/oldnewthing/archive/2005/02/01/364563.aspxtarget =_ blanktitle =New Window> ^ ]
希望这会有所帮助!
终于在这些旗帜的帮助下解决了:
https://msdn.microsoft.com/ en-us / library / windows / desktop / aa384129%28v = vs.85%29.aspx [ ^ ]
请参阅评论如下。
generally the intention is that the registry entry will be created under one of the paths only. So if the user has installed the 64 bit version, then i can not guess why would the application create the registry key under wow6432Node node also. (maybe registry redirection or something)
A check to determine whether the system is 64 bit or 32 bit is enough for this situation and then check for the key accordingly.
check out Raymond Chen's suggestion[^]
hope this helps !
was finally solved with the help of these flags:
https://msdn.microsoft.com/en-us/library/windows/desktop/aa384129%28v=vs.85%29.aspx[^]
please refer the comments below.
这篇关于使用VC ++访问注册表键路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!