1,105,375 Community Members

Editing Windows Registry

Member Avatar
krnekhelesh
Junior Poster
127 posts since Jul 2007
Reputation Points: 16 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

I want to create a C++ Program to edit the Windows Registry. For example to change the home page of internet explorer. But I don't know how to read or edit the help.

I am doing this program just for my own self and is not a part of homework.

Member Avatar
krnekhelesh
Junior Poster
127 posts since Jul 2007
Reputation Points: 16 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

I got the following source from the internet... but I don't know how to manipulate it for my convience

#include <windows.h>
#include <iostream>

int main () {

	HKEY hKey;				// Declare a key to store the result
	DWORD buffersize = 1024;	// Declare the size of the data buffer
	char* lpData = new char[buffersize];// Declare the buffer

	/* Open the Registry Key at the location 
	HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Main
	with read only access
	*/

	RegOpenKeyEx (HKEY_CURRENT_USER, 
	"Software\\Microsoft\\Internet Explorer\\Main",NULL,KEY_READ,&hKey);
	
	// Query the registry value
	RegQueryValueEx(hKey,"Start Page",NULL,NULL,(LPBYTE) lpData,&buffersize);
	
	// Print out the registry value
	std::cout << "Registry Key Open: memory location=" << hKey << "\n";
	std::cout << "Your Internet Start Page is " << lpData << "\n\n";

	// Close the Registry Key
	RegCloseKey (hKey);
	
	// Pause the system so there is time to read what is going on
	system("Pause");

	delete lpData;
}
Member Avatar
krnekhelesh
Junior Poster
127 posts since Jul 2007
Reputation Points: 16 [?]
Q&As Helped to Solve: 3 [?]
Skill Endorsements: 0 [?]
 
0
 

but the thing is it edits reads only strings... I want to read a value which has binary values.... How do I do that?

Member Avatar
vijayan121
Posting Virtuoso
1,769 posts since Dec 2006
Reputation Points: 1,097 [?]
Q&As Helped to Solve: 329 [?]
Skill Endorsements: 16 [?]
 
1
 

you still use RegQueryValueEx.

LONG WINAPI RegQueryValueEx( HKEY hKey, LPCTSTR lpValueName, 
            LPDWORD lpReserved,
            LPDWORD lpType, // will be set to the type of data 
                  // (eg. REG_BINARY if value was binary) 
            LPBYTE lpData, LPDWORD lpcbData );

see http://msdn2.microsoft.com/en-us/library/ms724884.aspx for the registry value types.

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article