用EVB怎样进行注册表编程?最好有完整代码。

解决方案 »

  1.   

    EVB 请问是什么?英文版的 VB  ?我只知道用VB 操作注册表有系列函数请到论坛右上角点击“搜索”,在搜索页面的“关键字”一栏填写“注册表”,然后搜索。
      

  2.   

    '
    ' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
    ' ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
    ' THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
    ' PARTICULAR PURPOSE.
    '
    ' This is "Sample Code" and is distributable subject to the terms of the end user license agreement.Option Explicit'storage for the open reg key
    Public hKey As Long
    'Registry manipulation functions
    Public Declare Function RegCreateKeyEx Lib "Coredll" Alias "RegCreateKeyExW" (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 Long, phkResult As Long, lpdwDisposition As Long) As Long
    Public Declare Function RegCloseKey Lib "Coredll" (ByVal hKey As Long) As Long
    Public Declare Function RegQueryValueEx Lib "Coredll" Alias "RegQueryValueExW" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, ByVal lpData As String, lpcbData As Long) As Long         ' Note that if you declare the lpData parameter as String, you must pass it By Value.
    Public Declare Function RegSetValueEx Lib "Coredll" Alias "RegSetValueExW" (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         ' Note that if you declare the lpData parameter as String, you must pass it By Value.
    Public Declare Function RegDeleteKey Lib "Coredll" Alias "RegDeleteKeyW" (ByVal hKey As Long, ByVal lpSubKey As String) As LongPrivate Const REG_NONE = (0)                         'No value type
    Private Const REG_SZ = (1)                           'Unicode nul terminated string
    Private Const REG_EXPAND_SZ = (2)                    'Unicode nul terminated string w/enviornment var
    Private Const REG_BINARY = (3)                       'Free form binary
    Private Const REG_DWORD = (4)                        '32-bit number
    Private Const REG_DWORD_LITTLE_ENDIAN = (4)          '32-bit number (same as REG_DWORD)
    Private Const REG_DWORD_BIG_ENDIAN = (5)             '32-bit number
    Private Const REG_LINK = (6)                         'Symbolic Link (unicode)
    Private Const REG_MULTI_SZ = (7)                     'Multiple Unicode strings
    Private Const REG_RESOURCE_LIST = (8)                'Resource list in the resource map
    Private Const REG_FULL_RESOURCE_DESCRIPTOR = (9)     'Resource list in the hardware description
    Private Const REG_RESOURCE_REQUIREMENTS_LIST = (10)'Registry Constants
    Public Const HKEY_CLASSES_ROOT = &H80000000
    Public Const HKEY_CURRENT_USER = &H80000001
    Public Const HKEY_LOCAL_MACHINE = &H80000002
    Public Const HKEY_USERS = &H80000003
    'Define severity codes
    Public Const ERROR_SUCCESS = 0
    Public Const ERROR_ACCESS_DENIED = 5
    Public Const ERROR_NO_MORE_ITEMS = 259
    'The registry key to create and edit
    Public Const REGKEY = "Software\Microsoft\RegDemo"'The two registry values
    Public Const Key1 = "String1"
    Public Const Key2 = "DWORD1"Public Const MAX_KEYLENGTH = 255
    '
    ' THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
    ' ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
    ' THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
    ' PARTICULAR PURPOSE.
    '
    ' This is "Sample Code" and is distributable subject to the terms of the end user license agreement.Option Explicit'Refresh the Current values of the reg keys
    'By examining the registry
    'hKey must have alread been opened with RegCreateKeyExPrivate Sub getKeys()
        Dim strValue As String
        Dim lngLen As Long
        Dim lngType As Long    'alloc storage for the value
        strValue = Space(MAX_KEYLENGTH)
        lngLen = MAX_KEYLENGTH
        
        'look in registry for REG_SZ type String1
        RegQueryValueEx hKey, Key1, 0, lngType, strValue, lngLen
        lblString.Caption = strValue    'reset the storage string
        strValue = Space(MAX_KEYLENGTH)
        lngLen = MAX_KEYLENGTH
        
        'look in registry for REG_DWORD DWORD1
        RegQueryValueEx hKey, Key2, 0, lngType, strValue, lngLen
        lblDword.Caption = strValueEnd SubPrivate Sub cmdRemove_Click()
        Dim lngResult As Long
        
        'Delete the created key and its values
        lngResult = RegDeleteKey(HKEY_CURRENT_USER, REGKEY)
        
        'Show that key is no longer present
        If lngResult = ERROR_SUCCESS Then
            lblString.Caption = ""
            lblDword.Caption = ""
        End If
                
    End SubPrivate Sub cmdSet_Click()
        Dim lngResult As Long
        Dim strValue As String
        
        'create the key if it does not exist or open it
        'hKey is a handle to the new or opened key
        'REGKEY is a string specifying the subkey
        
        lngResult = RegCreateKeyEx(HKEY_CURRENT_USER, REGKEY, 0, 0, 0, 0, 0, hKey, 0)
        
        If lngResult <> ERROR_SUCCESS Then
            MsgBox "Error Opening Registry key"
        Else
            strValue = txtDword.Text
            
            If IsNumeric(strValue) Then     'if DWORD1 is a number
                
                'set its value in the registry
                'Key2 is string naming the value, strValue holds the value
                RegSetValueEx hKey, Key2, 0, REG_DWORD, strValue, LenB(strValue)
                
                'set String1 key as well
                strValue = txtString.Text
                RegSetValueEx hKey, Key1, 0, REG_SZ, strValue, LenB(strValue)
            Else
                MsgBox "DWORD1 must be a number", , "Set Error"
            End If
            
            getKeys
        End If
        
        RegCloseKey hKey
    End SubPrivate Sub Form_Load()
        Dim lngResult As Long
        
        'create the key or open it if it already exists
        lngResult = RegCreateKeyEx(HKEY_CURRENT_USER, REGKEY, 0, 0, 0, 0, 0, hKey, 0)
        
        If lngResult <> ERROR_SUCCESS Then
            MsgBox "Error Opening Registry key"
        Else
            getKeys
        End If
        
        RegCloseKey hKey
        
    End SubPrivate Sub Form_OKClick()
        App.End
    End Sub