Results 1 to 6 of 6
  1. #1
    Join Date
    Apr 2005
    Posts
    203

    Talking Unanswered: Problem writing multiple values to registery

    Hi all i am usiing this code to write mulitiple values to registery but it only write one value. could any one help me make this code so that it write multiple values to registery. Currently it only writes nickname but not pwd value!!
    I tried this but gave me error :


    Code:
    'Save the value to the registry
        SaveString HKEY_CURRENT_USER, "Software\xyz\" + Text6.Text, "nickname",+Text7.Text "pwd", strString

    complete code :


    Code:
    Const REG_SZ = 1 ' Unicode nul terminated string
    Const REG_BINARY = 3 ' Free form binary
    Const HKEY_CURRENT_USER = &H80000001
    Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
    Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    Private Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hKey As Long, ByVal lpValueName As String) As Long
    Private Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    Private 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
    Private 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
    
    
    
    
    Sub SaveString(hKey As Long, strPath As String, strValue As String, strData As String)
        Dim Ret
        'Create a new key
        RegCreateKey hKey, strPath, Ret
        'Save a string to the key
        RegSetValueEx Ret, strValue, 0, REG_SZ, ByVal strData, Len(strData)
        'close the key
        RegCloseKey Ret
    End Sub
    Sub SaveStringLong(hKey As Long, strPath As String, strValue As String, strData As String)
        Dim Ret
        'Create a new key
        RegCreateKey hKey, strPath, Ret
        'Set the key's value
        RegSetValueEx Ret, strValue, 0, REG_BINARY, CByte(strData), 4
        'close the key
        RegCloseKey Ret
    End Sub
    
    Private Sub Command14_Click()
    'Dim strString As String
        Dim strString As String
        'Ask for a value
        'strString = InputBox("Please enter a value to be saved as a binary value in the registry.", App.Title)
        
    
        'Save the value to the registry
    
    
        SaveString HKEY_CURRENT_USER, "Software\xyz\" + Text6.Text, "nickname", strString
    
    '    SaveString HKEY_CURRENT_USER, "Software\xyz\" + Text6.Text, "nickname",+Text7.Text, "pwd", strString ===> did not work
        
     
    End Sub

  2. #2
    Join Date
    Jun 2006
    Location
    Colton, CA
    Posts
    26
    If you're only using CurrentUser - you can just use the SaveSetting method which is included with VB

    Code:
    SaveSetting ("xyz", "Options", "Nickname", text6.text)
    SaveSetting ("xyz", "Options", "Pwd", text7.text)
    Then use GetSetting() to retreive the values

    Code:
    strName = GetSetting("xyz", "Options", "Nickname", "default_name")
    strPwd = GetSetting("xyz", "Options", "pwd", "default_password")
    Geek it till it mHz

  3. #3
    Join Date
    Apr 2005
    Posts
    203
    Quote Originally Posted by spikey_richie
    If you're only using CurrentUser - you can just use the SaveSetting method which is included with VB

    Code:
    SaveSetting ("xyz", "Options", "Nickname", text6.text)
    SaveSetting ("xyz", "Options", "Pwd", text7.text)
    Then use GetSetting() to retreive the values

    Code:
    strName = GetSetting("xyz", "Options", "Nickname", "default_name")
    strPwd = GetSetting("xyz", "Options", "pwd", "default_password")
    Thank u for u reply. yes i only use current user.So u think your code will creat a key called newfolder inside sofware\xyz with 2 keys called Nickname and pwd? What components and refrence do i need to use this ? or just place :

    SaveSetting ("xyz", "Options", "Nickname", text6.text)
    SaveSetting ("xyz", "Options", "Pwd", text7.text)

    in command button. Furthermore, how to display all the keys not subkeys inside xyz\ and place it in drop downbox?Thanks

  4. #4
    Join Date
    Jun 2006
    Location
    Colton, CA
    Posts
    26
    1 ) as in the other thread, you don't need ANY of that API stuff
    Using SaveSetting, you SHOULD be able to create a new key. Be careful when using "", numeric values will not need the "" - and if you need to you can convert a numeric to string using str()

    2) Use GetSetting and read each of the values into variables. Then use nameOfComboBox.additem valueOfVariable
    Geek it till it mHz

  5. #5
    Join Date
    Jun 2006
    Location
    Colton, CA
    Posts
    26
    Geek it till it mHz

  6. #6
    Join Date
    Apr 2005
    Posts
    203
    Quote Originally Posted by spikey_richie
    If you're only using CurrentUser - you can just use the SaveSetting method which is included with VB

    Code:
    SaveSetting ("xyz", "Options", "Nickname", text6.text)
    SaveSetting ("xyz", "Options", "Pwd", text7.text)
    Then use GetSetting() to retreive the values

    Code:
    strName = GetSetting("xyz", "Options", "Nickname", "default_name")
    strPwd = GetSetting("xyz", "Options", "pwd", "default_password")
    Man it never works. i tried this and it shows red on both savSetting lines:
    Also your code will might not create a key with new 2 subkesys. the name of key folder is provided by text1 and value of subkey
    password is provided with text2 and value of subkey name is the same as newfolder key and provided by text1 . Just like this one :

    strString = Text1.Text
    strString2 = Text2.Text


    SaveString HKEY_CURRENT_USER, "Software\xyz\" + Text1.Text, "nickname", strString
    SaveString HKEY_CURRENT_USER, "Software\xyz\" + Text1.Text, "pwd", strString2

    Code:
    Sub SaveString(hKey As Long, strPath As String, strValue As String, strData As String)
        Dim Ret
        'Create a new key
        RegCreateKey hKey, strPath, Ret
        'Save a string to the key
        RegSetValueEx Ret, strValue, 0, REG_SZ, ByVal strData, Len(strData)
        'close the key
        RegCloseKey Ret
    End Sub
    Sub SaveStringLong(hKey As Long, strPath As String, strValue As String, strData As String)
        Dim Ret
        'Create a new key
        RegCreateKey hKey, strPath, Ret
        'Set the key's value
        RegSetValueEx Ret, strValue, 0, REG_BINARY, CByte(strData), 4
        'close the key
        RegCloseKey Ret
    End Sub
    
    
    Private Sub Command1_Click()
    
    SaveSetting ("xyz", "Options", "Nickname", text1.text)
    SaveSetting ("xyz", "Options", "Pwd", text1.text)
        
    End Sub
    Last edited by mehran; 06-21-06 at 07:48.

Posting Permissions

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