cast this
http://www.china-askpro.com/msg3/qa26.shtml

解决方案 »

  1.   

    JennyVenus:
    多谢!不过我没找到在Windows XP 的非管理员帐户下访问注册表的办法。
      

  2.   

    vb中使用系统注册表
    ini文件大多用来寸放自己界面或者初始化信息,而应用程序要使用系统信息或者说要得知已在系统注册过的其他程序的一些信息就要读去系统注册表了,比如有些应用需要使用调用ms outlook express就需要从hkey_local_machine\software\microsoft\outlook express\中的installroot中读取路径。 申明部分:option explicitpublic const read_control = &h20000public const standard_rights_read = (read_control)public const standard_rights_write = (read_control)public const key_query_value = &h1public const key_set_value = &h2public const key_create_sub_key = &h4public const key_enumerate_sub_keys = &h8public const key_notify = &h10public const key_create_link = &h20public const synchronize = &h100000public const standard_rights_all = &h1f0000public const key_read = ((standard_rights_read or key_query_value or key_enumerate_sub_keys or key_notify) and (not synchronize))public const key_write = ((standard_rights_write or key_set_value or key_create_sub_key) and (not synchronize))public const key_all_access = ((standard_rights_all or key_query_value or key_set_value or key_create_sub_key or key_enumerate_sub_keys or key_notify or key_create_link) and (not synchronize))public const key_execute = ((key_read) and (not synchronize))public const error_success = 0&declare function regopenkeyex lib "advapi32.dll" alias "regopenkeyexa" (byval hkey as long, byval lpsubkey as string, byval uloptions as long, byval samdesired as long, phkresult as long) as longdeclare function regqueryvalueex lib "advapi32.dll" alias "regqueryvalueexa" (byval hkey as long, byval lpvaluename as string, byval lpreserved as long, lptype as long, lpdata as any, lpcbdata as long) as longdeclare function regclosekey lib "advapi32.dll" (byval hkey as long) as longfunction sdagetregentry(strkey as string, strsubkeys as string, strvalname as string, lngtype as long) as stringon error goto sdagetregentry_errdim lngresult as long, lngkey as longdim lnghandle as long, lngcbdata as longdim strret as stringselect case strkeycase "hkey_classes_root": lngkey = &h80000000case "hkey_current_config": lngkey = &h80000005case "hkey_current_user": lngkey = &h80000001case "hkey_dyn_data": lngkey = &h80000006case "hkey_local_machine": lngkey = &h80000002case "hkey_performance_data": lngkey = &h80000004case "hkey_users": lngkey = &h80000003case else: exit functionend selectif not error_success = regopenkeyex(lngkey, strsubkeys, 0&, key_read, lnghandle) then exit functionlngresult = regqueryvalueex(lnghandle, strvalname, 0&, lngtype, byval strret, lngcbdata)strret = space(lngcbdata)lngresult = regqueryvalueex(lnghandle, strvalname, 0&, lngtype, byval strret, lngcbdata)if not error_success = regclosekey(lnghandle) then lngtype = -1&sdagetregentry = strretsdagetregentry_exit:on error goto 0exit functionsdagetregentry_err:lngtype = -1&msgbox err & "> " & error$, 16, "genutils/sdagetregentry"resume sdagetregentry_exitend function 看起来很复杂,用起来却简单的紧,这就达到了复杂的目的了。例如:使用outlook expressdim outlook_path as stringdim shstring as stringoutlook_path = sdagetregentry("hkey_local_machine", "software\microsoft\outlook express\", "installroot", 2)shstring = mid(trim(outlook_path), 1, len(outlook_path) - 1) & "\msimn.exe"shell shstring
      

  3.   

    多谢解答!我正在用vb写个应用程序,应用程序须将用户选择的数据存入注册表,
    下次启动时,程序从注册表读出数据建立界面。这种方式已在windows 98下通过,在XP的管理员帐户下也无问题。但在Windows XP的非管理员帐户下系统拒绝访问。因为用户通常不以管理员帐户登录,所以我必须解决系统拒绝访问注册表的问题。难道只能建立ini文件,放弃用注册表存储用户数据?