码迷,mamicode.com
首页 > 其他好文 > 详细

用installshield和C写的程序通过注册表进行通信

时间:2016-07-13 11:57:03      阅读:138      评论:0      收藏:0      [点我收藏+]

标签:

用installshield对注册表进行操作:
技术分享
技术分享
nRootKey = HKEY_LOCAL_MACHINE; 
RegDBSetDefaultRoot(nRootKey);//为设置默认5大注册表项的哪一个
RegDBKeyExist (regDbKey);//这个方法返回值为0表示regDbKey在注册表中存在,返回值<0表示不存在。
//如果不存在的话,我要创建这个项并在其中写入一下名字为Sanc的字段,并赋以初值,那么我调用这句话就行了:
RegDBSetKeyValueEx("SofeWare\\Clients", "Sanc", REGDB_STRING, "10", -1);//Clients键设置一个新值Sanc,如果不存在就不会设置值。
上图为Get得到键值。




C++对注册表进行操作:
技术分享
技术分享
HKEY hKey;
    HKEY hSubKey;
    DWORD dwValue = 1;
    char Buffer[] = "raw2rgb.dll";
     
    // 使用RegCreateKey能保证如果Software\daheng_directx不存在的话,创建一个。
    if (RegCreateKey(HKEY_LOCAL_MACHINE, "Software\\daheng_directx", &hKey) == ERROR_SUCCESS) {
        //
        // 在这里就可以使用hKey来操作daheng_directx这个KEY里面的值了。
        //
 
        if (RegSetValueEx(hKey, "AEC", 0, REG_DWORD, (CONST BYTE*)&dwValue, sizeof(DWORD)) == ERROR_SUCCESS) {
            printf("RegSetValueEx: AEC = %d\n", dwValue);
        }
 
        //
        // 如果想在Software\\daheng_directx创建一个plugins key,那么就不能再使用hKey了,需要
        // 重新获取这个结点的HKEY。
        //
         
        if (RegCreateKey(hKey, "plugins", &hSubKey) == ERROR_SUCCESS) {
            if (RegSetValueEx(hSubKey, "颜色校正插件", 0, REG_SZ, (CONST BYTE*)Buffer,strlen(Buffer) + 1) == ERROR_SUCCESS) {
                printf("RegSetValueEx: 颜色校正插件 = %s\n", Buffer);
            }
            RegCloseKey(hSubKey);
        }
    }
    RegCloseKey(hKey);



//==================================================================================================
int Write_reg_error()
{
char system[]="11";
int i=0;
HKEY hKey;
//RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SOFTWARE\\Clients\\WritePara",0,KEY_SET_VALUE,&hKey );//打开注册表,不存在时报错
if(RegCreateKey(HKEY_LOCAL_MACHINE, "SOFTWARE\\Clients\\WritePara", &hKey) != ERROR_SUCCESS)//打开注册表,不存在时创建。
{
printf("Error 1\n");
return -1;
}
if(RegSetValueEx(hKey, "AutoAdminLogon",0,REG_SZ,(const unsigned char*)system,sizeof(system)) != ERROR_SUCCESS)//对对应的键值写入数据
{
printf("Error 2\n");
return -1;
}
RegCloseKey(hKey);
scanf("%d", &i);
return 0;
}


















用installshield和C写的程序通过注册表进行通信

标签:

原文地址:http://blog.csdn.net/u011164819/article/details/51895754

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!