3 回答
TA贡献1864条经验 获得超6个赞
该函数是API函数,将下面代码保存为Reg.Bas就可以正常使用了。
'养成好习惯代表所有变量都需要先定义后使用
Option Explicit
'根键常数
Public Const HKEY_CLASSES_ROOT = &H80000000
Public Const HKEY_CURRENT_USER = &H80000001
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const HKEY_USERS = &H80000003
Public Const HKEY_PERFORMANCE_DATA = &H80000004
Public Const HKEY_CURRENT_CONFIG = &H80000005
Public Const HKEY_DYN_DATA = &H80000006
'键值类型
Public Const REG_NONE = 0
Public Const REG_SZ = 1 '字符串值
Public Const REG_EXPAND_SZ = 2
Public Const REG_BINARY = 3 '二进制值
Public Const REG_DWORD = 4 'DWORD 值
Public Const REG_DWORD_BIG_ENDIAN = 5
Public Const REG_MULTI_SZ = 7
'----声明有关注册表API函数 --Start----
'建立一个新的主键
Public Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" _
( _
ByVal hKey As Long, _
ByVal lpSubKey As String, _
ByRef phkResult As Long _
) As Long
'打开一个主键 返回0代表打开成功,返回2代表打开失败
Public Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" _
( _
ByVal hKey As Long, _
ByVal lpSubKey As String, _
ByRef phkResult As Long _
) As Long
'删除一个主键
Public Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" _
( _
ByVal hKey As Long, _
ByVal lpSubKey As String _
) As Long
'关闭一个主键 返回0代表关闭成功,6代表关闭失败
Public Declare Function RegCloseKey Lib "advapi32.dll" _
( _
ByVal hKey As Long _
) As Long
'创建或改变一个键值,lpData应由缺省的ByRef型改为ByVal型
Public Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" _
( _
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应由缺省的ByRef型改为ByVal型
Public Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" _
( _
ByVal hKey As Long, _
ByVal lpValueName As String, _
ByVal lpReserved As Long, _
ByRef lpType As Long, _
ByVal lpData As Any, _
ByRef lpcbData As Long _
) As Long
'删除一个键值
Public Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" _
( _
ByVal hKey As Long, _
ByVal lpValueName As String _
) As Long
'----声明有关注册表API函数 End----
TA贡献1824条经验 获得超6个赞
在声明里加上
Public Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
其他几个注册表函数也要声明
TA贡献1869条经验 获得超4个赞
API函数还没定义,不能直接调用
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 RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult 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
Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long
添加回答
举报