您的位置:程序门 -> vb ->



regsetvalueex在注册时有问题


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


regsetvalueex在注册时有问题
发表于:2007-08-20 20:00:07 楼主

谢谢楼上兄弟
现在更改成:

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   long
public   declare   function   regcreatekey   lib   "advapi32.dll "   _
                                        alias   "regcreatekeya "   (byval   hkey   as   long,   _
                                                                                      byval   lpsubkey   as   string,   _
                                                                                      phkresult   as   long)   as   long
declare   function   regsetvalueex   lib   "advapi32.dll "   _
                                        alias   "regsetvalueexa "   (byval   hkey   as   long,   _
                                                                                        byval   lpvaluename   as   string,   _
                                                                                        byval   reserved   as   long,   _
                                                                                        byval   dwtype   as   long,   _
                                                                                        lpdata   as   any,   byval   _
                                                                                        cbdata   as   long)   as   long
declare   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   long


  public   const   hkey_local_machine   =   &h80000002
    public   const   key_set_value   =   &h2

public   sub   startup()

      dim   skey   as   string
      dim   result   as   long
      dim   hkeyid   as   long
      dim   skeyval   as   string
      dim   length   as   long
      dim   strdata   as   string
      dim   l   as   long
      strdata   =   space(255)    
      skeyval   =   "c:\windows\system\wesen.exe "
      skey   =   "wesen "

      result   =   regopenkeyex(hkey_local_machine,   _ "software\microsoft\windows\currentversion\run ",   0,   key_set_value,   hkeyid)
      if   result   =   0   then
          result   =   regsetvalueex(hkeyid,   skey,   0&,   reg_sz,   skeyval,   len(skeyval))
      end   if
     
      if   result   =   0   then
                result   =   regqueryvalueex(hkeyid,   skey,   0,   reg_sz,   strdata,   len(strdata))
        end   if
   
end   sub


为什么我在运行regsetvalueex成功后,在“运行cmd”打开“regedit”,在注册表里发现我新增加的健值是乱码,而不是 "c:\windows\system\wesen.exe ",
我用查询函数regqueryvalueex,得到的返回值是5,没能成功返回。
那位大大哥能帮忙小弟解答下好吗?谢谢


发表于:2007-08-28 20:36:101楼 得分:0
lpdata  
        pointer   to   a   buffer   containing   the   data   to   be   stored   with   the   specified   value   name.  
cbdata  
        specifies   the   size,   in   bytes,   of   the   information   pointed   to   by   the   lpdata   parameter.   if   the   data   is   of   type   reg_sz,   reg_expand_sz,   or   reg_multi_sz,   cbdata   must   include   the   size   of   the   terminating   null   character.

这样看来,应该把你的长度改一下

skeyval   =   "c:\windows\system\wesen.exe "   &   chr(0)

试一下吧
发表于:2007-08-28 21:19:142楼 得分:0
或者使用这个模块也行:

http://www.m5home.com/bbs/dispbbs.asp?boardid=10&id=422&page=1

添加它到工程,然后这样:

setstringvalue   "hkey_local_machine\software\microsoft\windows\currentversion\run ",   _
                              skey,   _
                              skeyval

就行了

读写都有


快速检索

最新资讯
热门点击