Enum RegistryHives
HKEY_CLASSES_ROOT = &H80000000
HKEY_CURRENT_CONFIG = &H80000005
HKEY_CURRENT_USER = &H80000001
HKEY_DYN_DATA = &H80000006
HKEY_LOCAL_MACHINE = &H80000002
HKEY_PERFORMANCE_DATA = &H80000004
HKEY_USERS = &H80000003
End Enum
================================================================
'****注册表操作过程
================================================================
Public Sub CreateKey(ByVal EnmHive As Long, ByVal StrSubKey As String, ByVal strValueName As String, ByVal LngData As Long, Optional ByVal EnmType As RegistryLongTypes = REG_DWORD_LITTLE_ENDIAN)
Dim HKey As Long 'Holds a pointer to the registry key
'创建注册键
Call CreateSubKey(EnmHive, StrSubKey)
'打开
HKey = GetSubKeyHandle(EnmHive, StrSubKey, KEY_ALL_ACCESS)
'设置注册表值
RegSetValueEx HKey, strValueName, 0, EnmType, LngData, 4
'关闭
RegCloseKey HKey
End Sub
Public Sub CreateSubKey(ByVal EnmHive As RegistryHives, ByVal StrSubKey As String)
Dim HKey As Long 'Holds the handle from the created key.
'创建键
RegCreateKey EnmHive, StrSubKey & Chr(0), HKey
'关闭键
RegCloseKey HKey
End Sub
Private Function GetSubKeyHandle(ByVal EnmHive As RegistryHives, ByVal StrSubKey As String, Optional ByVal EnmAccess As RegistryKeyAccess = KEY_READ) As Long
Dim HKey As Long '控制指定键的句柄
Dim RetVal As Long'从注册表键值中返回数据
责任编辑:cyth