打印本文 打印本文 关闭窗口 关闭窗口
在VB中读写注册表函数源码
作者:武汉SEO闵涛  文章来源:敏韬网  点击数2507  更新时间:2009/4/23 18:57:39  文章录入:mintao  责任编辑:mintao
sp;         End If ''''rtn = ERROR_SUCCESS
''''=========================================================================================
        Case regGetKeyValue ''''=112   ''''取键值
''''=========================================================================================
            rtn = RegOpenKeyEx(RootKey, SubKey, 0, KEY_READ, hKey)
            If rtn = ERROR_SUCCESS Then ''''if the key could be opened
''''{

            Select Case regKeyType
''''----------------------------------------------------------------------------------------
            Case regTypeBinary      ''''=&H00000001        ''''Binary
''''KeyValue作为传值变量获得键值,调用示例:
''''Dim a As String
''''SysRegControl regHKEY_LOCAL_MACHINE, "jadgekylin\jklpos", "pos", a, regTypeBinary, regGetKeyValue
''''----------------------------------------------------------------------------------------
                  rtn = RegQueryValueEx(hKey, Key, 0, REG_BINARY, 0, lBufferSize) ''''get the value from the registry
                 sBuffer = Space(lBufferSize)
                 rtn = RegQueryValueEx(hKey, Key, 0, REG_BINARY, sBuffer, lBufferSize) ''''get the value from the registry
            If Not rtn = ERROR_SUCCESS Then   ''''if the was an error writting the value
                rtn = RegCloseKey(hKey)
                SysRegControl = False ''''调用失败
                Exit Function
            Else
                KeyValue = sBuffer
               
            End If
            rtn = RegCloseKey(hKey) ''''close the key

''''----------------------------------------------------------------------------------------
            Case regTypeDword   ''''=&H00000002    ''''DWORD
''''
''''KeyValue作为传值变量获得键值,调用示例:
''''Dim a As Long
''''SysRegControl regHKEY_LOCAL_MACHINE, "jadgekylin\jklpos", "pos", a, regTypeString, regGetKeyValue
''''----------------------------------------------------------------------------------------
                  rtn = RegQueryValueExA(hKey, Key, 0, REG_DWORD, lBuffer, 4) ''''get the value from the registry
            If Not rtn = ERROR_SUCCESS Then   ''''if the was an error writting the value
                rtn = RegCloseKey(hKey)
                SysRegControl = False ''''调用失败
                Exit Function
            Else
                KeyValue = lBuffer
            End If
            rtn = RegCloseKey(hKey) ''''close the key

''''----------------------------------------------------------------------------------------
            Case regTypeString  ''''=&H00000003    ''''String

''''KeyValue作为传值变量获得键值,调用示例:
''''Dim a As String
''''SysRegControl regHKEY_LOCAL_MACHINE, "jadgekylin\jklpos", "pos1", a, regTypeString, regGetKeyValue
''''----------------------------------------------------------------------------------------
                  sBuffer = Space(255)     ''''make a buffer
                      lBufferSize = Len(sBuffer)
                  rtn = RegQueryValueEx(hKey, Key, 0, REG_SZ, sBuffer, lBufferSize) ''''get the value from the registry
                  sBuffer = Trim(sBuffer)
                      sBuffer = Left(sBuffer, Len(sBuffer) - 1) ''''return the value to the user
            If Not rtn = ERROR_SUCCESS Then   ''''if the was an error writting the value
                rtn = RegCloseKey(hKey)
                SysRegControl = False ''''调用失败
                Exit Function
            Else
                KeyValue = sBuffer
               
            End If
            rtn = RegCloseKey(hKey) ''''close the key

''''----------------------------------------------------------------------------------------

            End Select
''''}
   
            End If ''''rtn = ERROR_SUCCESS


''''=========================================================================================
        Case regCreatKey    ''''=113   ''''创建子键

''''SubKey 是创建对象,Key,KeyValue为保留字,调用示例:
''''SysRegControl regHKEY_LOCAL_MACHINE, "jadgekylin\jklpos\pos", "", 0, regTypeDword, regCreatKey
''''=========================================================================================

           rtn = RegCreateKey(RootKey, SubKey, hKey) ''''create the key
           If Not rtn = ERROR_SUCCESS Then ''''if the key was created then
              rtn = RegCloseKey(hKey)  ''''close the key
              SysRegControl = False
              Exit Function
           End If

''''=========================================================================================
        Case regDeleteKeys  ''''=114   ''''删除末级子键同regDelAllKey

''''此处Key指定为SubKey下一级子键即被删除子键,SubKey可以为"",key若为"",则删除SubKey子键
''''调用示例:
''''SysRegControl regHKEY_LOCAL_MACHINE, "", "jadgekylin", "", regTypeBinary, regDeleteKeys
''''SysRegControl regHKEY_LOCAL_MACHINE, "jadgekylin", "", "", regTypeBinary, regDeleteKeys
''''SysRegControl regHKEY_LOCAL_MACHINE, "" , "jadgekylin", "", regTypeBinary, regDeleteKeys
''''=========================================================================================
        rtn = RegOpenKeyEx(RootKey, SubKey, 0, KEY_WRITE, hKey) ''''open the key
        If rtn = ERROR_SUCCESS Then ''''if the key could be opened then
                rtn = RegDeleteKey(hKey, Key) ''''delete the key
        Else
            rtn = RegCloseKey(hKey)  ''''close the key
            SysRegControl = False
            Exit Function
        End If

''''=========================================================================================
        Case regDelAllKey   ''''=115   ''''删除非末级子键,暂时同RegDeleteKeys
''''=========================================================================================
      

上一页  [1] [2] [3]  下一页

打印本文 打印本文 关闭窗口 关闭窗口