现在在学习对注册表的操作,但看不太董。我想把程序的一些初始默认参数,和一些其他参数保存在注册表中。请问哪位有关于注册表的系统知识的讲解。比如要操作注册表应先Create一个,最后要关闭句柄。谢谢!!!

解决方案 »

  1.   

    #include <windows.h>
    #include <stdio.h>
    void main()
    {
        HKEY hkey;
        char Author[100] = "reg operating";
        char Organization[100] = "Internet";
        char City[100] = "CHDU";
        bool State = true;
        unsigned char KeyBuffer[50];
        DWORD Type = 0;
        DWORD DataLen = 1024;
        memset(KeyBuffer, 0, sizeof(KeyBuffer));
        if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\A New Program\\Information", 0, KEY_ALL_ACCESS, &hkey) != ERROR_SUCCESS)
        {
            if (RegCreateKey(HKEY_CURRENT_USER, "Software\\A New Program\\Information", &hkey) != ERROR_SUCCESS)
            {
                printf("RegCreateKey failed with Erro \n");
                return ;
            }
        }
        if (RegSetValueEx(hkey, "Organization", 0, REG_SZ, (BYTE*)Organization, 100) != ERROR_SUCCESS)
        {
            printf("RegSetValueEx failed with Erro \n");
            return ;
        }
        if (RegSetValueEx(hkey, "Author", 0, REG_SZ, (BYTE*)Author, 100) != ERROR_SUCCESS)
        {
            printf("RegSetValueEx failed with   Erro \n");
            return ;
        }
        if (RegSetValueEx(hkey, "City", 0, REG_SZ, (BYTE*)City, 100) != ERROR_SUCCESS)
        {
            printf("RegSetValueEx failed with Erro \n");
            return ;
        }
        if (RegSetValueEx(hkey, "State", 0, REG_DWORD, (BYTE*) &State, 4) != ERROR_SUCCESS)
        {
            printf("RegSetValueEx failed with  Erro \n");
            return ;
        }
        if (RegCloseKey(hkey) != ERROR_SUCCESS)
        {
            printf("RegCloseKey failed with Erro \n");
            return ;
        }
        if (RegOpenKeyEx(HKEY_CURRENT_USER, "Software\\A New Program\\Information", 0, KEY_ALL_ACCESS, &hkey) == ERROR_SUCCESS)
        {
            if (RegQueryValueEx(hkey, "Author", 0, &Type, KeyBuffer, &DataLen) == ERROR_SUCCESS)
            {
                printf("Author:%s\n", KeyBuffer);
            }
            else
            {
                printf("RegQueryValueEx failed with Erro \n");
                return ;
            }
            if (RegQueryValueEx(hkey, "Organization", 0, &Type, KeyBuffer, &DataLen) == ERROR_SUCCESS)
            {
                printf("Organization:%s\n", KeyBuffer);
            }
            else
            {
                printf("RegQueryValueEx failed with Erro \n");
                return ;
            }
            if (RegQueryValueEx(hkey, "City", 0, &Type, KeyBuffer, &DataLen) == ERROR_SUCCESS)
            {
                printf("City:%s\n", KeyBuffer);
            }
            else
            {
                printf("RegQueryValueEx failed with Erro \n");
                return ;
            }
            if (RegQueryValueEx(hkey, "State", 0, &Type, KeyBuffer, &DataLen) == ERROR_SUCCESS)
            {
                State = KeyBuffer[0];
                if (State)
                {
                    printf("State:true\n");
                }
                else
                {
                    printf("State:false\n");
                }
            }
            else
            {
                printf("RegQueryValueEx failed with Erro \n");
                return ;
            }
            if (RegCloseKey(hkey) != ERROR_SUCCESS)
            {
                printf("RegCloseKey failed with Erro \n");
                return ;
            }
        }
        else
        {
            printf("RegOpenKeyEx failed with Erro \n");
            return ;
        }
      

  2.   

    我自己写过一个封装注册表的dll
    很实用
    qq可以high我
    358573906