Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to read values of the system's registry

Registry Handling

How to read values of the system's registry

by  Jay1Roy  Posted    (Edited  )
Hi all,

Here is a small piece of code that reads any key/value from registry. This program will compile right away (Win32), tested on VC++6.0 .
[blue]
Code:
#include "windows.h"
#include <winreg.h>
#include <stdio.h>

int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
	HKEY keyHandle;
	char rgValue [1024];
	char fnlRes [1024];
	DWORD size1;
	DWORD Type;

		if( RegOpenKeyEx(    HKEY_LOCAL_MACHINE, 
			"SOFTWARE\\Microsoft\\Windows\\CurrentVersion",0, 
			KEY_QUERY_VALUE, &keyHandle) == ERROR_SUCCESS)
			 {
				size1=1023;
				RegQueryValueEx( keyHandle, "Productid", NULL, &Type, 
					(LPBYTE)rgValue,&size1);
				sprintf(fnlRes,"Product ID of your Windows system is:: %s",rgValue);
			 }	 
		else strcpy(fnlRes,"Couldn't access system information!");
	
			RegCloseKey(keyHandle);

MessageBox(NULL, fnlRes, "Product ID of Windows", MB_SYSTEMMODAL|MB_ICONINFORMATION);

return 0;
}
[/blue]

I hope it helps, have fun! [thumbsup2]

Cheers!
Roy.

PS: This code snippet should be taken as a starting point, not as a final solution.
[peace]
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top