Solved

Writing binary values to the Registry

Posted on 2000-04-26
2
297 Views
Last Modified: 2013-11-20
I have to write binary values to the registry, where i store information about my program. Can anyone describe the general procedure of doing this? For example, open the key, write, close it, then read from it, change it.

A link to a good tutorial is cool too.
0
Comment
Question by:Mindo
2 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 50 total points
Comment Utility
In general, it works like this:

    HANDLE  g_hRegKey;


    // reading...

    DWORD   dwType;
    DWORD   dwSize  =   MAX_PATH;
    BOOL    bRC     =   TRUE;

    g_hRegKey   =   NULL;

    if  (   ERROR_SUCCESS   !=  RegOpenKeyEx    (    HKEY_LOCAL_MACHINE,
                                                     APPLICATION_REGPATH,
                                                     0,
                                                     KEY_ALL_ACCESS,
                                                    &g_hRegKey
                                                )
        )
        {
            DbgReport   (   L"RegOpenKeyEx() failed!!");

            return  (   FALSE);
        }

    dwType  =   REG_BINARY;
    dwSize  =   sizeof  (   g_awcRegUsr);

    if  (   ERROR_SUCCESS   !=  RegQueryValueEx (   g_hRegKey,
                                                    APPLICATION_USRNAME,
                                                    NULL,
                                                    &dwType,
                                                    ( LPBYTE) g_awcRegUsr,
                                                    &dwSize
                                                )
        )  
        {
            DbgReport   (   L"RegQueryValueEx() failed!!");

            bRC =   FALSE;
        }
   
    dwType  =   REG_BINARY;
    dwSize  =   sizeof  (   g_awcRegPwd);

    if  (   ERROR_SUCCESS   !=  RegQueryValueEx (   g_hRegKey,
                                                    APPLICATION_PASSWD,
                                                    NULL,
                                                    &dwType,
                                                    ( LPBYTE) g_awcRegPwd,
                                                    &dwSize
                                                )
        )  
        {
            DbgReport   (   L"RegQueryValueEx() failed!!");

            bRC =   FALSE;
        }


    // writing...

    if  (   ERROR_SUCCESS   !=  RegSetValueEx   (   g_hRegKey,
                                                    APPLICATION_USRNAME,
                                                    NULL,
                                                    REG_BINARY,
                                                    ( LPBYTE) g_awcRegUsr,
                                                    sizeof  (   g_awcRegUsr)
                                                )
        )   bRC =   FALSE;

    if  (   ERROR_SUCCESS   !=  RegSetValueEx   (   g_hRegKey,
                                                    APPLICATION_PASSWD,
                                                    NULL,
                                                    REG_BINARY,
                                                    ( LPBYTE) g_awcRegPwd,
                                                    sizeof  (   g_awcRegPwd)
                                                )
        )   bRC =   FALSE;


Feel free to ask if you need more information!
0
 
LVL 2

Author Comment

by:Mindo
Comment Utility
Thank you very much!
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now