Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here


Microsoft: Visual C++ FAQ

Registry Handling

How to read values of the system's registry by Jay1Roy
Posted: 18 Feb 04

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 .

#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,
            KEY_QUERY_VALUE, &keyHandle) == ERROR_SUCCESS)
                RegQueryValueEx( keyHandle, "Productid", NULL, &Type,
                sprintf(fnlRes,"Product ID of your Windows system is:: %s",rgValue);
        else strcpy(fnlRes,"Couldn't access system information!");

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

return 0;

I hope it helps, have fun!


PS: This code snippet should be taken as a starting point, not as a final solution.

Back to Microsoft: Visual C++ FAQ Index
Back to Microsoft: Visual C++ Forum

My Archive

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close