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




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

1 solution

Probably your application has not the right privileges needed to open a HKEY_LOCAL_MACHINE subtree. Anyway you have to check the return value code, as per the documentation[^] :

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.
 
Share this answer
 
Comments
Member 11460314 4-Aug-15 5:25am    
hey but i check with the same code to following path it is giving me correct output
path= "SOFTWARE\\Wow6432Node\\Microsoft\\Windows\\CurrentVersion\\Component Based Servicing\\Version"

similarly i crossed check with different path all worked well only i cannot access to reboot required which is currently present in my registry

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