| 发表于:2008-01-22 10:17:393楼 得分:0 |
楼上既然把位置找到了,我就给你提供一个模块,修改这2个位置即可完成你的要求 你仅需要修改注册表,不必创建,请适当修改 把下面的内容存成.bas(模块)文件,以后只要把这个文件加入你的工程就可以 直接用这些函数了 ' ----------------- ' advapi32 ' ----------------- ' function prototypes, constants, and type definitions ' for windows 32-bit registry api public const hkey_classes_root = &h80000000 public const hkey_current_user = &h80000001 public const hkey_local_machine = &h80000002 public const hkey_users = &h80000003 public const hkey_performance_data = &h80000004 public const error_success = 0& ' registry api prototypes declare function regclosekey lib "advapi32.dll" (byval hkey as long) a s long declare function regcreatekey lib "advapi32.dll" alias "regcreatekeya" (byval hkey as long, byval lpsubkey as string, phkresult as long) as long declare function regdeletekey lib "advapi32.dll" alias "regdeletekeya" (byval hkey as long, byval lpsubkey as string) as long declare function regdeletevalue lib "advapi32.dll" alias "regdeleteval uea" (byval hkey as long, byval lpvaluename as string) as long declare function regopenkey lib "advapi32.dll" alias "regopenkeya" (by val hkey as long, byval lpsubkey as string, phkresult as long) as long declare function regqueryvalueex lib "advapi32.dll" alias "regqueryval ueexa" (byval hkey as long, byval lpvaluename as string, byval lpreser ved as long, lptype as long, lpdata as any, lpcbdata as long) as long declare function regsetvalueex lib "advapi32.dll" alias "regsetvalueex a" (byval hkey as long, byval lpvaluename as string, byval reserved as long, byval dwtype as long, lpdata as any, byval cbdata as long) as l ong public const reg_sz = 1 ' unicode nul terminat ed string public const reg_dword = 4 ' 32-bit number public sub savekey(hkey as long, strpath as string) dim keyhand& r = regcreatekey(hkey, strpath, keyhand&) r = regclosekey(keyhand&) end sub public function getstring(hkey as long, strpath as string, strvalue as string) as string dim keyhand as long dim datatype as long dim lresult as long dim strbuf as string dim ldatabufsize as long dim intzeropos as integer r = regopenkey(hkey, strpath, keyhand) lresult = regqueryvalueex(keyhand, strvalue, 0&, lvaluetype, byval 0&, ldatabufsize) if lvaluetype = reg_sz then strbuf = string(ldatabufsize, " ") lresult = regqueryvalueex(keyhand, strvalue, 0&, 0&, byval strbuf, ldatabufsize) if lresult = error_success then intzeropos = instr(strbuf, chr$(0)) if intzeropos > 0 then getstring = left$(strbuf, intzeropos - 1) else getstring = strbuf end if end if end if end function public sub savestring(hkey as long, strpath as string, strvalue as str ing, strdata as string) dim keyhand as long dim r as long r = regcreatekey(hkey, strpath, keyhand) r = regsetvalueex(keyhand, strvalue, 0, reg_sz, byval strdata, len(str data)) r = regclosekey(keyhand) end sub function getdword(byval hkey as long, byval strpath as string, byval s trvaluename as string) as long dim lresult as long dim lvaluetype as long dim lbuf as long dim ldatabufsize as long dim r as long dim keyhand as long r = regopenkey(hkey, strpath, keyhand) ' get length/data type ldatabufsize = 4 lresult = regqueryvalueex(keyhand, strvaluename, 0&, lvaluetype, lbuf, ldatabufsize) if lresult = error_success then if lvaluetype = reg_dword then getdword = lbuf end if 'else ' call errlog("getdword-" & strpath, false) end if r = regclosekey(keyhand) end function function savedword(byval hkey as long, byval strpath as string, byval strvaluename as string, byval ldata as long) dim lresult as long dim keyhand as long dim r as long r = regcreatekey(hkey, strpath, keyhand) lresult = regsetvalueex(keyhand, strvaluename, 0&, reg_dword, ldat a, 4) 'if lresult <> error_success then call errlog("setdword", false) r = regclosekey(keyhand) end function public function deletekey(byval hkey as long, byval strkey as string) dim r as long r = regdeletekey(hkey, strkey) end function public function deletevalue(byval hkey as long, byval strpath as strin g, byval strvalue as string) dim keyhand as long r = regopenkey(hkey, strpath, keyhand) r = regdeletevalue(keyhand, strvalue) r = regclosekey(keyhand) end function | | |
|