这样用: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求得字符串的真实长度.
LenEx = LenB(StrConv(str, vbFromUnicode, 2052))
End FunctionRegSetValueEx hKeyID, sKey, 0, REG_SZ, ByVal sKeyVal, LenEx(sKeyVal)因为路径中有可能有汉字,所以用lenex求得字符串的真实长度.
LenEx = LenB(StrConv(str, vbFromUnicode, 2052))
End Function
使用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
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
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
Dim WSHShell
Set WSHShell = CreateObject("WScript.Shell")
WSHShell.RegWrite "HKEY_LOCAL_MACHINE\MyRegKey\", "Top level key"