你的函数用错了
Option ExplicitPrivate Const HKEY_CLASSES_ROOT = &H80000000
Private Const HKEY_CURRENT_CONFIG = &H80000005
Private Const HKEY_CURRENT_USER = &H80000001
Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Const HKEY_USERS = &H80000003
Private Const HKEY_PERFORMANCE_DATA = &H80000004
Private Const HKEY_DYN_DATA = &H80000006Private Const STANDARD_RIGHTS_ALL = &H1F0000
Private Const KEY_QUERY_VALUE = &H1
Private Const KEY_SET_VALUE = &H2
Private Const KEY_CREATE_SUB_KEY = &H4
Private Const KEY_ENUMERATE_SUB_KEYS = &H8
Private Const KEY_NOTIFY = &H10
Private Const KEY_CREATE_LINK = &H20
Private Const SYNCHRONIZE = &H100000
Private 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))
Private Const READ_CONTROL = &H20000
Private Const STANDARD_RIGHTS_WRITE = (READ_CONTROL)
Private Const KEY_WRITE = ((STANDARD_RIGHTS_WRITE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY) And (Not SYNCHRONIZE))
Private Const STANDARD_RIGHTS_READ = (READ_CONTROL)
Private Const KEY_READ = ((STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And (Not SYNCHRONIZE))
Private Const KEY_EXECUTE = ((KEY_READ) And (Not SYNCHRONIZE))Private Const REG_SZ = 1 ' Unicode nul terminated string
Private Const REG_EXPAND_SZ = 2 ' Unicode nul terminated string
Private Const REG_MULTI_SZ = 7 ' Multiple Unicode strings
Private Const REG_DWORD = 4 ' 32-bit number
Private Const REG_DWORD_BIG_ENDIAN = 5 ' 32-bit numberPrivate Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End TypePrivate 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
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegCreateKeyEx Lib "advapi32.dll" Alias "RegCreateKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal Reserved As Long, ByVal lpClass As String, ByVal dwOptions As Long, ByVal samDesired As Long, lpSecurityAttributes As SECURITY_ATTRIBUTES, phkResult As Long, lpdwDisposition As Long) As Long
Private Declare Function RegQueryValue Lib "advapi32.dll" Alias "RegQueryValueA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal lpValue As String, lpcbValue As Long) As Long
Private 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 ' Note that if you declare the lpData parameter as String, you must pass it By Value.
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegSetValue Lib "advapi32.dll" Alias "RegSetValueA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal dwType As Long, ByVal lpData As String, ByVal cbData As Long) As Long
Private 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 ' Note that if you declare the lpData parameter as String, you must pass it By Value.
Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As LongPrivate Sub Devide(ByVal Key As String, ByRef cKey As Long, ByRef sKey As String)
Select Case Left(Key, InStr(Key, "\") - 1)
Case "HKEY_CLASSES_ROOT"
cKey = HKEY_CLASSES_ROOT
Case "HKEY_CURRENT_USER"
cKey = HKEY_CURRENT_USER
Case "HKEY_LOCAL_MACHINE"
cKey = HKEY_LOCAL_MACHINE
Case "HKEY_USERS"
cKey = HKEY_USERS
Case "HKEY_PERFORMANCE_DATA"
cKey = HKEY_PERFORMANCE_DATA
Case "HKEY_CURRENT_CONFIG"
cKey = HKEY_CURRENT_CONFIG
Case "HKEY_DYN_DATA"
cKey = HKEY_DYN_DATA
End Select
sKey = Mid(Key, InStr(Key, "\") + 1)
End SubPublic Function GetRegDefaultValue(ByVal Key As String) As String
Dim ret As Long, cKey As Long, sKey As String, lenS As Long, S As String
Devide Key, cKey, sKey
lenS = 80
S = String(lenS, Chr(0))
ret = RegQueryValue(cKey, sKey, S, lenS)
If ret = 0 Then
S = Left(S, InStr(S, Chr(0)) - 1)
If S = " " Then
S = "(未设置数值)"
End If
End If
GetRegDefaultValue = S
End FunctionPublic Function GetRegValue(ByVal Key As String, ByVal Name As String) As Variant
Dim ret As Long, cKey As Long, sKey As String, hKey As Long, lenData As Long, typeData As Long
Devide Key, cKey, sKey
ret = RegOpenKeyEx(cKey, sKey, 0, KEY_READ, hKey)
If ret <> 0 Then Exit Function
ret = RegQueryValueEx(hKey, Name, 0, typeData, ByVal vbNullString, lenData)
If ret <> 0 Then
RegCloseKey hKey
Exit Function
End If
Select Case typeData
Case REG_SZ, REG_EXPAND_SZ, REG_MULTI_SZ
Dim S As String
S = String(lenData, Chr(0))
RegQueryValueEx hKey, Name, 0, typeData, ByVal S, lenData
If typeData = REG_SZ Then
S = Left(S, InStr(S, Chr(0)) - 1)
GetRegValue = S
End If
Case REG_DWORD, REG_DWORD_BIG_ENDIAN
Dim L As Long
RegQueryValueEx hKey, Name, 0, typeData, L, lenData
GetRegValue = L
End Select
RegCloseKey hKeyEnd Function
Option ExplicitPrivate Const HKEY_CLASSES_ROOT = &H80000000
Private Const HKEY_CURRENT_CONFIG = &H80000005
Private Const HKEY_CURRENT_USER = &H80000001
Private Const HKEY_LOCAL_MACHINE = &H80000002
Private Const HKEY_USERS = &H80000003
Private Const HKEY_PERFORMANCE_DATA = &H80000004
Private Const HKEY_DYN_DATA = &H80000006Private Const STANDARD_RIGHTS_ALL = &H1F0000
Private Const KEY_QUERY_VALUE = &H1
Private Const KEY_SET_VALUE = &H2
Private Const KEY_CREATE_SUB_KEY = &H4
Private Const KEY_ENUMERATE_SUB_KEYS = &H8
Private Const KEY_NOTIFY = &H10
Private Const KEY_CREATE_LINK = &H20
Private Const SYNCHRONIZE = &H100000
Private 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))
Private Const READ_CONTROL = &H20000
Private Const STANDARD_RIGHTS_WRITE = (READ_CONTROL)
Private Const KEY_WRITE = ((STANDARD_RIGHTS_WRITE Or KEY_SET_VALUE Or KEY_CREATE_SUB_KEY) And (Not SYNCHRONIZE))
Private Const STANDARD_RIGHTS_READ = (READ_CONTROL)
Private Const KEY_READ = ((STANDARD_RIGHTS_READ Or KEY_QUERY_VALUE Or KEY_ENUMERATE_SUB_KEYS Or KEY_NOTIFY) And (Not SYNCHRONIZE))
Private Const KEY_EXECUTE = ((KEY_READ) And (Not SYNCHRONIZE))Private Const REG_SZ = 1 ' Unicode nul terminated string
Private Const REG_EXPAND_SZ = 2 ' Unicode nul terminated string
Private Const REG_MULTI_SZ = 7 ' Multiple Unicode strings
Private Const REG_DWORD = 4 ' 32-bit number
Private Const REG_DWORD_BIG_ENDIAN = 5 ' 32-bit numberPrivate Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End TypePrivate 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
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegCreateKeyEx Lib "advapi32.dll" Alias "RegCreateKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal Reserved As Long, ByVal lpClass As String, ByVal dwOptions As Long, ByVal samDesired As Long, lpSecurityAttributes As SECURITY_ATTRIBUTES, phkResult As Long, lpdwDisposition As Long) As Long
Private Declare Function RegQueryValue Lib "advapi32.dll" Alias "RegQueryValueA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal lpValue As String, lpcbValue As Long) As Long
Private 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 ' Note that if you declare the lpData parameter as String, you must pass it By Value.
Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegSetValue Lib "advapi32.dll" Alias "RegSetValueA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal dwType As Long, ByVal lpData As String, ByVal cbData As Long) As Long
Private 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 ' Note that if you declare the lpData parameter as String, you must pass it By Value.
Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As LongPrivate Sub Devide(ByVal Key As String, ByRef cKey As Long, ByRef sKey As String)
Select Case Left(Key, InStr(Key, "\") - 1)
Case "HKEY_CLASSES_ROOT"
cKey = HKEY_CLASSES_ROOT
Case "HKEY_CURRENT_USER"
cKey = HKEY_CURRENT_USER
Case "HKEY_LOCAL_MACHINE"
cKey = HKEY_LOCAL_MACHINE
Case "HKEY_USERS"
cKey = HKEY_USERS
Case "HKEY_PERFORMANCE_DATA"
cKey = HKEY_PERFORMANCE_DATA
Case "HKEY_CURRENT_CONFIG"
cKey = HKEY_CURRENT_CONFIG
Case "HKEY_DYN_DATA"
cKey = HKEY_DYN_DATA
End Select
sKey = Mid(Key, InStr(Key, "\") + 1)
End SubPublic Function GetRegDefaultValue(ByVal Key As String) As String
Dim ret As Long, cKey As Long, sKey As String, lenS As Long, S As String
Devide Key, cKey, sKey
lenS = 80
S = String(lenS, Chr(0))
ret = RegQueryValue(cKey, sKey, S, lenS)
If ret = 0 Then
S = Left(S, InStr(S, Chr(0)) - 1)
If S = " " Then
S = "(未设置数值)"
End If
End If
GetRegDefaultValue = S
End FunctionPublic Function GetRegValue(ByVal Key As String, ByVal Name As String) As Variant
Dim ret As Long, cKey As Long, sKey As String, hKey As Long, lenData As Long, typeData As Long
Devide Key, cKey, sKey
ret = RegOpenKeyEx(cKey, sKey, 0, KEY_READ, hKey)
If ret <> 0 Then Exit Function
ret = RegQueryValueEx(hKey, Name, 0, typeData, ByVal vbNullString, lenData)
If ret <> 0 Then
RegCloseKey hKey
Exit Function
End If
Select Case typeData
Case REG_SZ, REG_EXPAND_SZ, REG_MULTI_SZ
Dim S As String
S = String(lenData, Chr(0))
RegQueryValueEx hKey, Name, 0, typeData, ByVal S, lenData
If typeData = REG_SZ Then
S = Left(S, InStr(S, Chr(0)) - 1)
GetRegValue = S
End If
Case REG_DWORD, REG_DWORD_BIG_ENDIAN
Dim L As Long
RegQueryValueEx hKey, Name, 0, typeData, L, lenData
GetRegValue = L
End Select
RegCloseKey hKeyEnd Function
解决方案 »
- 关于键盘记录~~~~~~~~~~~~
- 如何将picturebox中的内容保存为wmf文件?
- 求助!!!VB中编写播放器的问题????
- 急求控件VSLIGHT.OCX,VSVIEW6.OCX,VSFLEX6D.OCX,TEECHART.OCX
- 又没有可以访问局域网内其它电脑的又dirlistbox,drivelistbox功能的控件
- 请问有谁做过把文件拷贝到磁带机这样的程序?
- 向大侠求救!!!!!!(系统关机菜单的调用)
- 在线给100分:如何用ADO修改一个表结构(删除、增加、修改字段)?
- 怎样改变进程条的颜色,或者哪里有好看的进程条控件下载?急急急急急!
- 求解????????????????????????
- 请教高人,高难度挑战!!!!!!!(另有1000分相送)
- 紧急求救!100分相送
Const HKEY_LOCAL_MACHINE = &H80000002
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Private Declare Function RegEnumKeyEx Lib "advapi32.dll" Alias "RegEnumKeyExA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpName As String, lpcbName As Long, ByVal lpReserved As Long, ByVal lpClass As String, lpcbClass As Long, lpftLastWriteTime As Any) As Long
Private Declare Function RegEnumValue Lib "advapi32.dll" Alias "RegEnumValueA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal lpValueName As String, lpcbValueName As Long, ByVal lpReserved As Long, lpType As Long, lpData As Byte, lpcbData As Long) As Long
Private Sub Form_Paint()
Dim hKey As Long, Cnt As Long, sSave As String
'Clear the form
Me.Cls
Me.Print "RegEnumKeyEx"
'Open a registry key
RegOpenKey HKEY_LOCAL_MACHINE, "Enum", hKey
Do
'Create a buffer
sSave = String(255, 0)
'Enumerate the keys
If RegEnumKeyEx(hKey, Cnt, sSave, 255, 0, vbNullString, ByVal 0&, ByVal 0&) <> 0 Then Exit Do
'Print the result to the form
Me.Print StripTerminator(sSave)
Cnt = Cnt + 1
Loop
'Close the registry key
RegCloseKey hKey
Me.Print vbCrLf + "RegEnumValue:"
'Open a new key
RegOpenKey HKEY_CURRENT_CONFIG, "Display\Fonts", hKey
Cnt = 0
Do
'Create a buffer
sSave = String(255, 0)
'enumerate the values
If RegEnumValue(hKey, Cnt, sSave, 255, 0, ByVal 0&, ByVal 0&, ByVal 0&) <> 0 Then Exit Do
'pritn the results to the form
Me.Print StripTerminator(sSave)
Cnt = Cnt + 1
Loop
'Close the registry
RegCloseKey hKey
End Sub
'This function is used to stripoff all the unnecessary chr$(0)'s
Private Function StripTerminator(sInput As String) As String
Dim ZeroPos As Integer
'Search the first chr$(0)
ZeroPos = InStr(1, sInput, vbNullChar)
If ZeroPos > 0 Then
StripTerminator = Left$(sInput, ZeroPos - 1)
Else
StripTerminator = sInput
End If
End Function
dim strname as string
dim t(1000) as byte
strname=space(255)
call regopenkey_(hkey_local_machine,"software\microsoft\windows\currentversion",j_hwnd)
call RegEnumValue(j_hwnd,0,strname,255,0,0,t(0),1000)
试一下
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