Results 1 to 22 of 22

Thread: Reading and Writing and Deleting from registry

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2003
    Posts
    601

    Reading and Writing and Deleting from registry

    I need to read and write from the registry as well as deleting entrys. Anyone got a simple example on how to do it.

    I also need to know which encryption method I should use to store passwords in the registry?
    Last edited by psychotomus; Jul 29th, 2007 at 01:01 PM.

  2. #2
    Addicted Member Kal-El's Avatar
    Join Date
    Jun 2007
    Location
    Fortress of solitude
    Posts
    179

    Re: Reading and Writing and Deleting from registry

    Mentalis has a good example.

    «Source Code»«plugins»«skin»«fav apps»«Winamp en español»«Nsis en español»
    So what if your signature move is driving a tractor? I think it's adorable. - Lois ("Crimson")
    Don't forget to when your question is resolved ...and the people who help

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2003
    Posts
    601

    Re: Reading and Writing and Deleting from registry

    Doesn't show how to create sub-directorys in the registry. Do I just add the / for the path?

    like
    vb Code:
    1. RegCreateKeyEx HKEY_CURRENT_USER, "Sim-Chat", 0, "REG_DWORD", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, ByVal 0&, Result, Ret
    2.  
    3. RegCreateKeyEx HKEY_CURRENT_USER, "Sim-Chat/Users", 0, "REG_DWORD", REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, ByVal 0&, Result, Ret

    guess i'll give it a try. bbl. =)

  4. #4
    Addicted Member Kal-El's Avatar
    Join Date
    Jun 2007
    Location
    Fortress of solitude
    Posts
    179

    Re: Reading and Writing and Deleting from registry

    Use this..."\"...not "/".
    Other thing..I recommend in order to write REG_DWORD values to use this code style example:
    vb Code:
    1. Public Function WriteRegDWORD(ByVal h_Key As Long, ByVal lpcszPath As String, ByVal lpcszField As String, ByVal dwData As Long) As Boolean
    2. Dim hKey As Long
    3. Dim bRet As Boolean
    4. If RegCreateKeyEx(h_Key, lpcszPath, 0, 0, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, 0, hKey, 0) <> ERROR_SUCCESS Then
    5.     WriteRegDWORD = False
    6. Else
    7.     If RegSetValueEx(hKey, lpcszField, 0, REG_DWORD, dwData, Len(dwData)) = ERROR_SUCCESS Then
    8.         bRet = True
    9.     Else
    10.         bRet = False
    11.     End If
    12.     RegCloseKey hKey
    13. End If
    14. WriteRegDWORD = bRet
    15. End Function
    To use something like this:
    vb Code:
    1. WriteRegDWORD HKEY_LOCAL_MACHINE, "Software\Joel", "dwValueToWrite", 69
    Remember: this is an example..change it according to your needs.

    «Source Code»«plugins»«skin»«fav apps»«Winamp en español»«Nsis en español»
    So what if your signature move is driving a tractor? I think it's adorable. - Lois ("Crimson")
    Don't forget to when your question is resolved ...and the people who help

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2003
    Posts
    601

    Re: Reading and Writing and Deleting from registry

    Thanks Kal. Great example.

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2003
    Posts
    601

    Re: Reading and Writing and Deleting from registry

    I keep getting a type mismatch and can't figure out why. I copyed your function line for line =). any ideas why? I also have all constants and api functions correct.

    vb Code:
    1. If chkSavePassword.Value = vbChecked Then
    2.         If WriteRegDWORD(HKEY_LOCAL_MACHINE, "Software\Sim-Chat\Users\" & MyUserName & "\Login", "Password", txtPassword.Text) = False Then
    3.             MsgBox "error"
    4.         End If
    5.     Else
    6.         If WriteRegDWORD(HKEY_LOCAL_MACHINE, "Software\Sim-Chat\Users\" & MyUserName & "\Login", "Password", "") = False Then
    7.             MsgBox "error"
    8.         End If
    9.     End If

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2003
    Posts
    601

    Re: Reading and Writing and Deleting from registry

    got it fixed ;]

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2003
    Posts
    601

    Re: Reading and Writing and Deleting from registry

    We'll I thought I had it. Now I cant insert value's into the Keys. =(

  9. #9

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2003
    Posts
    601

    Re: Reading and Writing and Deleting from registry

    nevermind. got that fixed now too. kek

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2003
    Posts
    601

    Re: Reading and Writing and Deleting from registry

    Now I can't read my values.

    Code:
    Function RegQueryStringValue(ByVal hKey As Long, ByVal strValueName As String) As String
        Dim lResult As Long, lValueType As Long, strBuf As String, lDataBufSize As Long
        Dim strData As Integer
        'retrieve nformation about the key
        lResult = RegQueryValueEx(hKey, strValueName, 0, lValueType, ByVal 0, lDataBufSize)
        If lResult = 0 Then
            If lValueType = REG_SZ Then
                'Create a buffer
                strBuf = String(lDataBufSize, Chr$(0))
                'retrieve the key's content
                lResult = RegQueryValueEx(hKey, strValueName, 0, 0, ByVal strBuf, lDataBufSize)
                If lResult = 0 Then
                    'Remove the unnecessary chr$(0)'s
                    RegQueryStringValue = Left$(strBuf, InStr(1, strBuf, Chr$(0)) - 1)
                End If
            ElseIf lValueType = REG_BINARY Then
                'retrieve the key's value
                lResult = RegQueryValueEx(hKey, strValueName, 0, 0, strData, lDataBufSize)
                If lResult = 0 Then
                    RegQueryStringValue = strData
                End If
            ElseIf lValueType = REG_DWORD Then
                'retrieve the key's value
                lResult = RegQueryValueEx(hKey, strValueName, 0, 0, strData, lDataBufSize)
                If lResult = 0 Then
                    RegQueryStringValue = strData
                End If
            End If
        End If
    End Function
    my lValueType is a DWORD. returns a #.

  11. #11
    Addicted Member Kal-El's Avatar
    Join Date
    Jun 2007
    Location
    Fortress of solitude
    Posts
    179

    Re: Reading and Writing and Deleting from registry

    When reading values you must use RegOpenKeyEx.

    «Source Code»«plugins»«skin»«fav apps»«Winamp en español»«Nsis en español»
    So what if your signature move is driving a tractor? I think it's adorable. - Lois ("Crimson")
    Don't forget to when your question is resolved ...and the people who help

  12. #12

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2003
    Posts
    601

    Re: Reading and Writing and Deleting from registry

    Code:
    Function ReadRegDWORD(path As String) As Long
    
    
    RegOpenKeyEx HKEY_CURRENT_USER, path, 0, KEY_ALL_ACCESS, ReadRegDWORD
    
    End Function
    I must be missing something here. keeps returning 0 when i use
    ReadRegDWORD ("Software\Sim-Chat\Users\" & cmbUserName.Text & "\Login\Password") Where Password is the DWORD and not a Key

    if I use
    ReadRegDWORD ("Software\Sim-Chat\Users\" & cmbUserName.Text & "\Login")
    it returns a #

  13. #13
    Addicted Member Kal-El's Avatar
    Join Date
    Jun 2007
    Location
    Fortress of solitude
    Posts
    179

    Re: Reading and Writing and Deleting from registry

    No, sir....RegOpenKeyEx is only step one of three:
    RegOpenKeyEx
    RegQueryValueEx
    RegCloseKey
    See an example.
    Also try google sometime

    «Source Code»«plugins»«skin»«fav apps»«Winamp en español»«Nsis en español»
    So what if your signature move is driving a tractor? I think it's adorable. - Lois ("Crimson")
    Don't forget to when your question is resolved ...and the people who help

  14. #14

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2003
    Posts
    601

    Re: Reading and Writing and Deleting from registry

    1 last question. swear =)

    WHen it inserts the data into the registry. it encrypts it and when I receive it, it doesnt decrypt it. How am I suppose to decrypt it?

  15. #15
    Addicted Member Kal-El's Avatar
    Join Date
    Jun 2007
    Location
    Fortress of solitude
    Posts
    179

    Re: Reading and Writing and Deleting from registry

    Ok..

    Windows encrypts registry values for security reasons..but using the advapi functions like RegQueryValueEx, you shouldn't botther decrypt them your self.

    If you want to encrypt entries you'll have to write your own algorithm for encrypt and decrypt.

    «Source Code»«plugins»«skin»«fav apps»«Winamp en español»«Nsis en español»
    So what if your signature move is driving a tractor? I think it's adorable. - Lois ("Crimson")
    Don't forget to when your question is resolved ...and the people who help

  16. #16

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2003
    Posts
    601

    Re: Reading and Writing and Deleting from registry

    no. what i'm saying is when I insert a value into the registry, it encrypts it. but when I use RegQueryValueEx. it returns the encrypted entry, it doesn't decrypt it.

  17. #17
    Addicted Member Kal-El's Avatar
    Join Date
    Jun 2007
    Location
    Fortress of solitude
    Posts
    179

    Re: Reading and Writing and Deleting from registry

    Quote Originally Posted by psychotomus
    no. what i'm saying is when I insert a value into the registry, it encrypts it. but when I use RegQueryValueEx. it returns the encrypted entry, it doesn't decrypt it.
    Wait! That's no true!
    You must getting wrong values or something went wrong...

    «Source Code»«plugins»«skin»«fav apps»«Winamp en español»«Nsis en español»
    So what if your signature move is driving a tractor? I think it's adorable. - Lois ("Crimson")
    Don't forget to when your question is resolved ...and the people who help

  18. #18
    Fanatic Member Mxjerrett's Avatar
    Join Date
    Apr 2006
    Location
    Oklahoma
    Posts
    939

    Re: Reading and Writing and Deleting from registry

    Wow you guys are doing it the hard way. All you need to use is this code. Put this in the declarations section

    Code:
    Dim SScript
    Set SScript = CreateObject("WScript.Shell")
    To write to the registry

    Code:
    SScript.RegWrite "KEY", "DATA"
    To read:

    Code:
    label1.caption=SScript.RegRead("KEY")


    (I do not take credit for this code. Jazz00006 posted this on another site)

    If a post has been helpful please rate it.
    If your question has been answered, pull down the tread tools and mark it as resolved.

  19. #19

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2003
    Posts
    601

    Re: Reading and Writing and Deleting from registry

    Quote Originally Posted by Mxjerrett
    Wow you guys are doing it the hard way. All you need to use is this code. Put this in the declarations section

    Code:
    Dim SScript
    Set SScript = CreateObject("WScript.Shell")
    To write to the registry

    Code:
    SScript.RegWrite "KEY", "DATA"
    To read:

    Code:
    label1.caption=SScript.RegRead("KEY")


    (I do not take credit for this code. Jazz00006 posted this on another site)

    where at does it write that data at in the registry?

  20. #20
    Fanatic Member Mxjerrett's Avatar
    Join Date
    Apr 2006
    Location
    Oklahoma
    Posts
    939

    Re: Reading and Writing and Deleting from registry

    SScript.RegWrite "KEY", "DATA" writes it to the registry. Replace KEY with the location and DATA with the data you want to supply.

    If a post has been helpful please rate it.
    If your question has been answered, pull down the tread tools and mark it as resolved.

  21. #21

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2003
    Posts
    601

    Re: Reading and Writing and Deleting from registry

    where at in the registry i am asking?

  22. #22
    Fanatic Member Mxjerrett's Avatar
    Join Date
    Apr 2006
    Location
    Oklahoma
    Posts
    939

    Re: Reading and Writing and Deleting from registry

    Where ever you specify. You replace KEY with where you want it and wallah, your data is displayed in the registry, where ever you told it to.

    If a post has been helpful please rate it.
    If your question has been answered, pull down the tread tools and mark it as resolved.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width