这样用:Public Function LenEx(ByVal str As String) As Long
    LenEx = LenB(StrConv(str, vbFromUnicode, 2052))
End FunctionRegSetValueEx hKeyID, sKey, 0, REG_SZ, ByVal sKeyVal, LenEx(sKeyVal)因为路径中有可能有汉字,所以用lenex求得字符串的真实长度.

解决方案 »

  1.   

    楼上兄弟lenex函数在那里找到的,通知一声
      

  2.   

    就是lenb 和 strconv两个函数的应用呀.Public Function LenEx(ByVal str As String) As Long
        LenEx = LenB(StrConv(str, vbFromUnicode, 2052))
    End Function
      

  3.   

    出的什么错?
    使用RegOpenKeyEx比较好Public 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 Const ERROR_SUCCESS = 0&
    Public Const REG_SZ = 1                         ' Unicode nul terminated stringdim hkey as longif RegOpenKeyEx( HKEY_LOCAL_MACHINE, "Software\Microsoft\Windows\CurrentVersion\Run", 0, KEY_WRITE, &hkey ) = ERROR_SUCCESS  then
    '打开注册表中的相应项
    RegSetValueEx( hkey, "Laker", 0, REG_SZ, "fdsafdsafdsafdsafds", 100 );
    RegCloseKey( hkey );
    end if
      

  4.   

    VB操作注册表:
    http://www.sqreg.com/file/vb/reg_01.htm
    http://www.sqreg.com/file/vb/reg_02.htm
    http://www.sqreg.com/file/vb/reg_03.htm
    http://www.sqreg.com/file/vb/reg_04.htm
    http://www.sqreg.com/file/vb/reg_05.htm
    http://www.sqreg.com/file/vb/reg_06.htm
    http://www.sqreg.com/file/vb/reg_07.htm
      

  5.   

    Public Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    Public Declare Function RegSetvalueEx Lib "advapi32.dll" (ByVal hKey As Long, ByVal lpvalueName As String, ByVal Reserved As Long, ByVal dwType As Long, byval lpData As Any, ByVal cbData As Long) As Long
    在lpData As Any 前加入ByVal
      

  6.   

    试一试下面代码
    Dim WSHShell
    Set WSHShell = CreateObject("WScript.Shell")
    WSHShell.RegWrite "HKEY_LOCAL_MACHINE\MyRegKey\", "Top level key"
      

  7.   

    对了,还得引用一个名为scrrun.dll的文件,位置在c:\windows下