glorylandhyf

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

在使用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");

 

 

posted on 2012-10-15 15:09  glorylandhyf  阅读(682)  评论(0编辑  收藏  举报