Contents
'--------------------------------------------------------------- '-注册表 API 声明... '--------------------------------------------------------------- 
Private Declare Function RegCloseKey Lib "advapi32" (ByVal hKey As Long) As Long 
Private Declare Function RegCreateKeyEx Lib "advapi32" 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, ByRef lpSecurityAttributes As SECURITY_ATTRIBUTES, ByRef phkResult As Long, ByRef lpdwDisposition As Long) As Long 
Private Declare Function RegOpenKeyEx Lib "advapi32" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, ByRef phkResult As Long) As Long 
Private Declare Function RegQueryValueEx Lib "advapi32" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, ByRef lpType As Long, ByVal lpData As String, ByRef lpcbData As Long) As Long 
Private Declare Function RegSetValueEx Lib "advapi32" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, ByVal lpData As String, ByVal cbData 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 RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long 
'--------------------------------------------------------------- '- 注册表 Api 常数... '--------------------------------------------------------------- ' Reg Data Types... 
Const REG_SZ = 1 ' Unicode空终结字符串 
Const REG_EXPAND_SZ = 2 ' Unicode空终结字符串 
Const REG_DWORD = 4 ' 32-bit 数字 ' 注册表创建类型值... 
Const REG_OPTION_NON_VOLATILE = 0 ' 当系统重新启动时,关键字被保留 ' 注册表关键字安全选项... 
Const READ_CONTROL = &H20000 
Const KEY_QUERY_VALUE = &H1 
Const KEY_SET_VALUE = &H2 
Const KEY_CREATE_SUB_KEY = &H4 
Const KEY_ENUMERATE_SUB_KEYS = &H8 
Const KEY_NOTIFY = &H10 
Const KEY_CREATE_LINK = &H20 
Const KEY_READ = KEY_QUERY_VALUE + KEY_ENUMERATE_SUB_KEYS + KEY_NOTIFY + READ_CONTROL 
Const KEY_WRITE = KEY_SET_VALUE + KEY_CREATE_SUB_KEY + READ_CONTROL 
Const KEY_EXECUTE = KEY_READ 
Const KEY_ALL_ACCESS = KEY_QUERY_VALUE + KEY_SET_VALUE + _ KEY_CREATE_SUB_KEY + KEY_ENUMERATE_SUB_KEYS + _ KEY_NOTIFY + KEY_CREATE_LINK + READ_CONTROL ' 注册表关键字根类型... 
Const HKEY_CLASSES_ROOT = &H80000000 
Const HKEY_CURRENT_USER = &H80000001 
Const HKEY_LOCAL_MACHINE = &H80000002 
Const HKEY_USERS = &H80000003 
Const HKEY_PERFORMANCE_DATA = &H80000004 ' 返回值... 
Const ERROR_NONE = 0 
Const ERROR_BADKEY = 2 
Const ERROR_ACCESS_DENIED = 8 
Const ERROR_SUCCESS = 0 '--------------------------------------------------------------- '- 注册表安全属性类型... '--------------------------------------------------------------- 
Private Type SECURITY_ATTRIBUTES nLength As Long lpSecurityDescriptor As Long bInheritHandle As Boolean End Type 
Private Sub Form_Load() 
Dim priKey As Long 
Dim subKey As Long 
Dim res As Long 
Dim tempKey As Long 
res = RegOpenKeyEx(HKEY_CURRENT_USER, "SoftWare", 0, KEY_ALL_ACCESS, tempKey) 
MsgBox res 
res = RegOpenKeyEx(tempKey, "UTC", 0, KEY_ALL_ACCESS, tempKey) 
MsgBox res 
res = RegCreateKey(tempKey, "KeyAssign", subKey) 
res = RegOpenKeyEx(tempKey, "KeyAssign", 0, KEY_ALL_ACCESS, tempKey) 
MsgBox res 
MsgBox tempKey 
Call RegSetValueEx(tempKey, "Location", 0, REG_MULTI_SZ, "asdfsdf", 100)
Contents