Editing binary registry keys

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jester

    Editing binary registry keys

    'This is the code i have so far:

    Private Declare Function RegCloseKey Lib "advapi32.d ll" (ByVal hKey As _
    Long) As Long
    Private Declare Function RegOpenKey Lib "advapi32.d ll" Alias _
    "RegOpenKey A" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult _
    As Long) As Long
    Private Declare Function RegQueryValueEx Lib "advapi32.d ll" Alias _
    "RegQueryValueE xA" (ByVal hKey As Long, ByVal lpValueName As String, _
    ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As _
    Long) As Long
    Private Declare Function RegEnumValue Lib "advapi32.d ll" Alias _
    "RegEnumVal ueA" (ByVal hKey As Long, ByVal dwIndex As Long, ByVal _
    lpValueName As String, lpcbValueName As Long, ByVal lpReserved As _
    Long, lpType As Long, lpData As Any, lpcbData As Long) As Long


    Private Const REG_SZ = 1 ' Unicode nul terminated String
    Private Const REG_EXPAND_SZ = 2
    Private Const REG_DWORD = 4 ' 32-bit number
    Private Const HKEY_CLASSES_RO OT = &H80000000
    Private Const HKEY_CURRENT_US ER = &H80000001
    Private Const HKEY_LOCAL_MACH INE = &H80000002
    Private Const HKEY_USERS = &H80000003
    Private Const REG_BINARY = 3

    Private Declare Function RegCreateKey Lib "advapi32.d ll" Alias _
    "RegCreateK eyA" (ByVal hKey As Long, ByVal lpSubKey As String, _
    phkResult As Long) As Long
    Private Declare Function RegSetValueEx Lib "advapi32.d ll" 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

    Private Function SaveString(hKey As Long, strPath As String, strValue As
    String, strdata As String) As Long
    Dim keyhandle As Long
    Dim r As Long
    Dim lngRet As Long

    r = RegCreateKey(hK ey, strPath, keyhandle)
    lngRet = RegSetValueEx(k eyhandle, strValue, 0, REG_BINARY, ByVal strdata,
    Len(strdata))
    r = RegCloseKey(key handle)
    SaveString = lngRet
    End Function

    Private Function Get_Value() As String
    Get_Value = GetString(HKEY_ LOCAL_MACHINE, "SYSTEM\x", "key")
    End Function

    Private Function Set_Value(ByVal strValue As String)
    Dim a As Long
    a = SaveString(HKEY _LOCAL_MACHINE, "SYSTEM\x", "key", strValue)
    SaveString HKEY_LOCAL_MACH INE, "SYSTEM\x", "key", strValue
    End Function

    Public Function GetString(hKey As Long, strPath As String, 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
    Dim r As Long
    Dim lValueType As Long
    r = RegOpenKey(hKey , strPath, KeyHand)
    lResult = RegQueryValueEx (KeyHand, strValue, 0&, lValueType, ByVal 0&,
    lDataBufSize)
    If lValueType = REG_BINARY Then
    strBuf = String(lDataBuf Size, " ")
    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

    Private Sub Command1_Click( )
    Text1 = Get_Value
    End Sub

    Private Sub Command2_Click( )
    Set_Value (Text2)
    End Sub


    'Unfortuneatly, although it edits the proper binary key, the string you
    enter into text2 does not match the data in the key. Entering a "0" really
    enters "30". I need the key to be "01 00 00 00".


  • Raoul Watson

    #2
    Re: Editing binary registry keys


    "Jester" <chill381@comca st.net> wrote in message
    news:ubidncUbpt [email protected]. ..
    [color=blue]
    > 'Unfortuneatly, although it edits the proper binary key, the string you
    > enter into text2 does not match the data in the key. Entering a "0" really
    > enters "30". I need the key to be "01 00 00 00".
    >[/color]

    The ASCII text "0" is 48. In hexadecimal it is 30. So it is doing what it
    suppose to do.
    If you want to write hex 00, you need to write CHR$(0)


    Comment

    • Jester

      #3
      Re: Editing binary registry keys


      "Raoul Watson" <WatsonR@Intell igenCIA.com> wrote in message
      news:1fNEb.89$Y [email protected] nilink.net...[color=blue]
      >
      > "Jester" <chill381@comca st.net> wrote in message
      > news:ubidncUbpt [email protected]. ..
      >[color=green]
      > > 'Unfortuneatly, although it edits the proper binary key, the string you
      > > enter into text2 does not match the data in the key. Entering a "0"[/color][/color]
      really[color=blue][color=green]
      > > enters "30". I need the key to be "01 00 00 00".
      > >[/color]
      >
      > The ASCII text "0" is 48. In hexadecimal it is 30. So it is doing what it
      > suppose to do.
      > If you want to write hex 00, you need to write CHR$(0)
      >
      >[/color]
      i knew it was doing what it was supposed to, its just that i was trying to
      circumvent how it does it. Thanks for the CHR$(0) tip, i'll try it out, and
      let you know if it works.


      Comment

      • Jester

        #4
        Re: Editing binary registry keys


        "Raoul Watson" <WatsonR@Intell igenCIA.com> wrote in message
        news:1fNEb.89$Y [email protected] nilink.net...[color=blue]
        >
        > "Jester" <chill381@comca st.net> wrote in message
        > news:ubidncUbpt [email protected]. ..
        >[color=green]
        > > 'Unfortuneatly, although it edits the proper binary key, the string you
        > > enter into text2 does not match the data in the key. Entering a "0"[/color][/color]
        really[color=blue][color=green]
        > > enters "30". I need the key to be "01 00 00 00".
        > >[/color]
        >
        > The ASCII text "0" is 48. In hexadecimal it is 30. So it is doing what it
        > suppose to do.
        > If you want to write hex 00, you need to write CHR$(0)
        >
        >[/color]
        Thanks, it works now. You're a life saver.


        Comment

        Working...