| 发表于:2008-01-18 15:39:3018楼 得分:0 |
public function getkeyvaluetype(byval keyroot as keyroot, byval keyname as string, byval checkvaluename as string) as valuetype dim f as filetime, countkey as long, countvalue as long, maxlenkey as long, maxlenvalue as long dim l as long, s as string, strtmp as string, inttmp as long, valuename() as string, valuetype() as valuetype ' 打开一个已存在的注册表关键字... success = regopenkeyex(keyroot, keyname, 0, key_all_access, hkey) if success <> error_success then getkeyvaluetype = 0: regclosekey hkey: exit function ' 获得一个已打开的注册表关键字的信息... success = regqueryinfokey(hkey, vbnullstring, byval 0&, byval 0&, countkey, maxlenkey, byval 0&, countvalue, maxlenvalue, byval 0&, byval 0&, f) if success <> error_success then getkeyvaluetype = 0: regclosekey hkey: exit function if countvalue <> 0 then redim valuename(countvalue - 1) as string ' 重新定义数组, 使用数组大小与注册表关键字的子键数量匹配 redim valuetype(countvalue - 1) 'as long ' 重新定义数组, 使用数组大小与注册表关键字的子键数量匹配 for i = 0 to countvalue - 1 strtmp = string(255, vbnullchar) 'space(255) l = 255 regenumvalue hkey, i, byval strtmp, l, 0, inttmp, byval 0&, byval 0& valuetype(i) = inttmp valuename(i) = left(strtmp, l) if instr(valuename(i), vbnullchar) - 1 <> -1 then valuename(i) = left$(valuename(i), instr(valuename(i), vbnullchar) - 1) end if if valuename(i) = checkvaluename then getkeyvaluetype = valuetype(i) exit function end if next i end if ' 关闭注册表关键字... regclosekey hkey end function public function getkeyinfo(keyroot as keyroot, keyname as string, subkeyname() as string, valuename() as string, valuetype() as valuetype, optional countkey as long, optional countvalue as long, optional maxlenkey as long, optional maxlenvalue as long) as boolean dim f as filetime dim l as long, s as string, strtmp as string, inttmp as long ' 打开一个已存在的注册表关键字... success = regopenkeyex(keyroot, keyname, 0, key_all_access, hkey) if success <> error_success then getkeyinfo = false: regclosekey hkey: exit function ' 获得一个已打开的注册表关键字的信息... success = regqueryinfokey(hkey, vbnullstring, byval 0&, byval 0&, countkey, maxlenkey, byval 0&, countvalue, maxlenvalue, byval 0&, byval 0&, f) if success <> error_success then getkeyinfo = false: regclosekey hkey: exit function if countkey <> 0 then redim subkeyname(countkey - 1) as string ' 重新定义数组, 使用数组大小与注册表关键字的子项数量匹配 for i = 0 to countkey - 1 strtmp = string(255, vbnullchar) 'space(255) l = 255 regenumkeyex hkey, i, byval strtmp, l, 0, vbnullstring, byval 0&, f subkeyname(i) = left(strtmp, l) if instr(subkeyname(i), vbnullchar) - 1 <> -1 then subkeyname(i) = left$(subkeyname(i), instr(subkeyname(i), vbnullchar) - 1) end if next i ' 下面的二重循环对字符串数组进行冒泡排序 for i = 0 to ubound(subkeyname) for j = i + 1 to ubound(subkeyname) if subkeyname(i) > subkeyname(j) then s = subkeyname(i) subkeyname(i) = subkeyname(j) subkeyname(j) = s end if next j next i end if if countvalue <> 0 then redim valuename(countvalue - 1) as string ' 重新定义数组, 使用数组大小与注册表关键字的子键数量匹配 redim valuetype(countvalue - 1) 'as long ' 重新定义数组, 使用数组大小与注册表关键字的子键数量匹配 for i = 0 to countvalue - 1 strtmp = string(255, vbnullchar) 'space(255) l = 255 regenumvalue hkey, i, byval strtmp, l, 0, inttmp, byval 0&, byval 0& valuetype(i) = inttmp valuename(i) = left(strtmp, l) if instr(valuename(i), vbnullchar) - 1 <> -1 then valuename(i) = left$(valuename(i), instr(valuename(i), vbnullchar) - 1) end if next i ' 下面的二重循环对字符串数组进行冒泡排序 for i = 0 to ubound(valuename) for j = i + 1 to ubound(valuename) if valuename(i) > valuename(j) then s = valuename(i) valuename(i) = valuename(j) valuename(j) = s end if next j next i end if ' 关闭注册表关键字... regclosekey hkey getkeyinfo = true ' 返回函数值 end function public function regdeletesubkey(hkey as keyroot, subkey as string) as boolean '删除目录 'mhkey是指主键的名称,subkey是指路径 dim ret as long, index as long, hname as string dim hsubkey as long ret = regopenkey(hkey, subkey, hsubkey) if ret <> 0 then regdeletesubkey = false exit function end if ret = regdeletekey(hsubkey, "") if ret <> 0 then '如果删除失败则认为是nt则用递归方法删除目录 hname = string(256, chr(0)) while regenumkey(hsubkey, 0, hname, len(hname)) = 0 and _ regdeletesubkey(hsubkey, hname) wend ret = regdeletekey(hsubkey, "") end if regdeletesubkey = (ret = 0) regclosekey hsubkey '删除打开的键值,释放内存 end function | | |
|