CSDN博客

img bluesky35

[原创]在VB6.0中访问注册表

发表于2004/9/23 15:49:00  2178人阅读

                                                                                   作者:bluesky35(蓝天)

'以下声明定义在模块中:
Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
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 String, ByVal cbData As Long) As Long
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_SZ = 1&

'以下操作定义在FORM中
'写注册表
Private Sub Command1_Click()
    Dim ret As Long, rtn As Long, hKey As Long, hKey2 As Long, Entry As String, value As String
    Entry = "EventMessageFile"
    value = "C:/WINNT/Microsoft.NET/Framework/v1.1.4322/EventLogMessages.dll"
    '创建键值
    ret = RegCreateKey(HKEY_LOCAL_MACHINE, "SYSTEM/CurrentControlSet/Services/Eventlog/Eventlog2/Eventlog2", hKey)
    '写入值
    If Not ret Then
        rtn = RegSetValueEx(hKey, Entry, 0, REG_SZ, ByVal value, Len(value)) 
        If Not rtn Then
            MsgBox "Write Successed!"
        End If
        '关闭
        rtn = RegCloseKey(hKey) 
    Else
        MsgBox "Create Subkey Operation Fail"
    End If
End Sub

最后祝你好运

0 0

相关博文

我的热门文章

img
取 消
img