我这里在csdn一收,csdn网站就出问题了,唉.麻烦还是给俺举个简单例子吧

解决方案 »

  1.   

    用getsetting函数就可以了。
    具体用法MSDN有。
      

  2.   

    或用APIDeclare Function RegQueryValue Lib "advapi32.dll" Alias "RegQueryValueA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal lpValue As String, lpcbValue As Long) As Long
      

  3.   

    http://www.vbeden.com/vbcode/code_1/code_1-2.htm
      

  4.   

    看下面:
      '以下是为了操作注册表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 ERROR_SUCCESS = 0&' Registry API prototypesDeclare Function RegCloseKey Lib "advapi32.dll" (ByVal HKEY As Long) As Long
    Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal HKEY As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal HKEY As Long, ByVal lpSubKey As String) As Long
    Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal HKEY As Long, ByVal lpValueName As String) As Long
    Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal HKEY As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal HKEY As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData 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, lpData As Any, ByVal cbData As Long) As Long
    Public Const REG_SZ = 1                         ' Unicode nul terminated string
    Public Const REG_DWORD = 4                      ' 32-bit number
    Public Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As LongPublic Sub savekey(HKEY As Long, strPath As String)
    Dim keyhand&
    r = RegCreateKey(HKEY, strPath, keyhand&)
    r = RegCloseKey(keyhand&)
    End SubPublic Function getstring(HKEY As Long, ByVal strPath As String, ByVal strValue As String)Dim keyhand As Long
    Dim datatype As Long
    Dim lResult As Long
    Dim strBuf As String
    Dim lDataBufSize As Long
    Dim intZeroPos As Integer
    r = RegOpenKey(HKEY, strPath, keyhand)
    lResult = RegQueryValueEx(keyhand, strValue, 0&, lValueType, ByVal 0&, lDataBufSize)
    If lValueType = REG_SZ Then
        strBuf = String(lDataBufSize, " ")
        lResult = RegQueryValueEx(keyhand, strValue, 0&, 0&, ByVal strBuf, lDataBufSize)
        If lResult = ERROR_SUCCESS Then
            intZeroPos = InStr(strBuf, Chr$(0))
            If intZeroPos > 0 Then
                getstring = Left$(strBuf, intZeroPos - 1)
            Else
                getstring = strBuf
            End If
        End If
    End If
    End Function
    Public Sub savestring(HKEY As Long, ByVal strPath As String, ByVal strValue As String, ByVal strdata As String)
    Dim keyhand As Long
    Dim r As Long
    r = RegCreateKey(HKEY, strPath, keyhand)
    r = RegSetValueEx(keyhand, strValue, 0, REG_SZ, ByVal strdata, Len(strdata))
    r = RegCloseKey(keyhand)
    End Sub
    Function getdword(ByVal HKEY As Long, ByVal strPath As String, ByVal strValueName As String) As Long
    Dim lResult As Long
    Dim lValueType As Long
    Dim lBuf As Long
    Dim lDataBufSize As Long
    Dim r As Long
    Dim keyhand As Longr = RegOpenKey(HKEY, strPath, keyhand) ' Get length/data type
    lDataBufSize = 4
        
    lResult = RegQueryValueEx(keyhand, strValueName, 0&, lValueType, lBuf, lDataBufSize)If lResult = ERROR_SUCCESS Then
        If lValueType = REG_DWORD Then
            getdword = lBuf
        End If
    'Else
    '    Call errlog("GetDWORD-" & strPath, False)
    End Ifr = RegCloseKey(keyhand)
        
    End FunctionFunction SaveDword(ByVal HKEY As Long, ByVal strPath As String, ByVal strValueName As String, ByVal lData As Long)
        Dim lResult As Long
        Dim keyhand As Long
        Dim r As Long
        r = RegCreateKey(HKEY, strPath, keyhand)
        lResult = RegSetValueEx(keyhand, strValueName, 0&, REG_DWORD, lData, 4)
        'If lResult <> error_success Then Call errlog("SetDWORD", False)
        r = RegCloseKey(keyhand)
    End FunctionPublic Function DeleteKey(ByVal HKEY As Long, ByVal strKey As String)
    Dim r As Long
    r = RegDeleteKey(HKEY, strKey)
    End FunctionPublic Function DeleteValue(ByVal HKEY As Long, ByVal strPath As String, ByVal strValue As String)
    Dim keyhand As Long
    r = RegOpenKey(HKEY, strPath, keyhand)
    r = RegDeleteValue(keyhand, strValue)
    r = RegCloseKey(keyhand)
    End Function例子:
       '添加DNS主机名
       HKEY = HKEY_LOCAL_MACHINE
        strPath = "System\CurrentControlSet\Services\VxD\MSTCP"
        strValue = "HostName"
         strdata = "Mycomputer"
      If strdata <> getstring(HKEY, strPath, strValue) Then
          Call savestring(HKEY, strPath, strValue, strdata)
        End If'删除DNS主机名
       Dim HKEY As Long
        HKEY = HKEY_LOCAL_MACHINE
        strPath = "System\CurrentControlSet\Services\VxD\MSTCP"
        strValue = "HostName"                       
         t = DeleteValue(HKEY, strPath, strValue)