InstallShield 2010读写注册表的脚本函数编写

在使用InstallShield制作安装包的时候,常常要使用到对注册表的读写等操作,这里提供自己写的注册表读写函数。

读注册表函数ReadReg:

 1 // 申明
 2 prototype ReadReg(NUMBER, STRING, STRING)
 3  
 4 // 函数体        
 5 function ReadReg(nRootKey, szKey, szKeyName)
 6     NUMBER nType, nSize;
 7     STRING resString, szClass;
 8     STRING szKeyValue;
 9     INT res;
10 
11 begin
12     //设置根目录
13     RegDBSetDefaultRoot(nRootKey);
14     
15     //初始化键值
16     nType = REGDB_STRING;
17     nSize = -1;
18 
19     //判断项是否存在
20     if RegDBKeyExist(szKey) < 0 then
21         // 不存在
22         MessageBox("Inexsiteance", WARNING);
23     else
24         // 存在
25         res = RegDBGetKeyValueEx(szKey, szKeyName, nType, szKeyValue, nSize); 
26 
27         if res < 0 then
28             MessageBox("无法读取注册表信息", SEVERE);
29             abort;  
30         else
31             return szKeyValue;
32         endif;
33 
34     endif; 
35             
36 end;
37 
38 // 调用举例
39 STRING RegString;
40  
41 RegString = ReadReg(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", "HotKeysCmds");

写注册表函数WriteReg:

 1 // 申明
 2 prototype WriteReg(NUMBER, STRING, STRING, STRING);
 3  
 4 // 函数体
 5 function INT writeReg(nRootKey, szKey, szKeyName, szKeyValue)
 6 NUMBER nType, nSize;
 7 STRING resString, szClass;
 8 INT res;
 9 
10 begin
11     //设置根目录
12     RegDBSetDefaultRoot(nRootKey);
13     
14     //判断项是否存在
15     if RegDBKeyExist(szKey) < 0 then
16         //不存在
17         RegDBCreateKeyEx(szKey, "");
18         MessageBox("Inexsiteance", WARNING);
19     endif;
20 
21     //初始化键值
22     nType = REGDB_STRING;
23     nSize = -1;
24 
25     res = RegDBSetKeyValueEx(szKey, szKeyName, nType, szKeyValue, nSize);
26     if (res < 0) then
27         MessageBox("Write Reg Wrong", WARNING);
28     endif;                
29 
30     RegDBCreateKeyEx(szKey, szClass);
31 
32     return res;
33 end;
34  
35 // 调用举例
36 INT res;
37  
38 res = WriteReg(HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", "abcdefg", "abcd");

 

 

转载于:https://www.cnblogs.com/glorylandhyf/archive/2012/10/15/2724333.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值