Click here to Skip to main content
15,941,293 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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;
	}
}



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?
Posted

1 solution

hi,
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.
 
Share this answer
 
v2
Comments
chandanadhikari 6-Aug-15 3:02am    
can be done by using preprocessor macros also.
http://stackoverflow.com/questions/1505582/determining-32-vs-64-bit-in-c
Member 11460314 6-Aug-15 3:05am    
Hey my intension is whether it be 64 bit OS or 32 bit OS it must check at both this paths:
"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\WindowsUpdate\\Auto Update\\Power" as well as this
"SOFTWARE\\wow6432Node\\Microsoft\\Windows\\CurrentVersion\\WindowsUpdate\\Auto Update\\Power"
inorder to ensure whether power Folder is present or not in both the views.
chandanadhikari 6-Aug-15 3:08am    
terribly sorry for the mistake. I will change my answer soon.
Member 11460314 6-Aug-15 3:32am    
No worries but i hope you understood the requirements properly. i am being trying this from past 2 days and now it has become a challenge for me
chandanadhikari 6-Aug-15 3:37am    
could not test this with code right now but these flags might help you :
https://msdn.microsoft.com/en-us/library/windows/desktop/aa384129(v=vs.85).aspx

also :
http://stackoverflow.com/questions/12796624/key-wow64-32key-and-key-wow64-64key

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900