Results 1 to 11 of 11

Thread: how can i change an regedit key?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2002
    Location
    Disney Land
    Posts
    190

    Question how can i change an regedit key?

    i wanna change a regedit key in vb, how can i do that?

  2. #2

    Thread Starter
    Addicted Member
    Join Date
    Feb 2002
    Location
    Disney Land
    Posts
    190

    .

    can someone help me??????????

  3. #3
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Feb 2002
    Location
    Disney Land
    Posts
    190

    .

    sorry im a newbie in vb, how can i like edit "local_machine, software, microsoft, msn, theres a key right here" <<< how can i edit that key?

  5. #5
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373
    look at the function

    SetKeyValue

    in that module i linked to you.. it has full commented instructions on what parameters you have to pass for it to change the desired key

  6. #6
    Software Eng. Megatron's Avatar
    Join Date
    Mar 1999
    Location
    Canada
    Posts
    11,286
    VB Code:
    1. Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hkey As Long) As Long
    2. Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    3. Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hkey As Long, ByVal lpSubKey As String) As Long
    4. Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hkey As Long, ByVal lpValueName As String) As Long
    5. Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    6. 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
    7. 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
    8. Public Const HKEY_CLASSES_ROOT = &H80000000
    9. Public Const HKEY_CURRENT_USER = &H80000001
    10. Public Const HKEY_LOCAL_MACHINE = &H80000002
    11. Public Const HKEY_USERS = &H80000003
    12. Public Const HKEY_PERFORMANCE_DATA = &H80000004
    13. Public Const REG_SZ = 1
    14.  
    15. Function RegQueryStringValue(ByVal hkey As Long, ByVal strValueName As String)
    16.     Dim lResult As Long
    17.     Dim lValueType As Long
    18.     Dim strBuf As String
    19.     Dim lDataBufSize As Long
    20.    
    21.     On Error GoTo 0
    22.     lResult = RegQueryValueEx(hkey, strValueName, 0&, lValueType, ByVal 0&, lDataBufSize)
    23.     If lResult = ERROR_SUCCESS Then
    24.         If lValueType = REG_SZ Then
    25.             strBuf = String(lDataBufSize, " ")
    26.             lResult = RegQueryValueEx(hkey, strValueName, 0&, 0&, ByVal strBuf, lDataBufSize)
    27.             If lResult = ERROR_SUCCESS Then
    28.                 RegQueryStringValue = StripTerminator(strBuf)
    29.             End If
    30.         End If
    31.     End If
    32. End Function
    33.  
    34. Public Function GetString(hkey As Long, strpath As String, strvalue As String)
    35.     Dim keyhand&
    36.     Dim datatype&
    37.     r = RegOpenKey(hkey, strpath, keyhand&)
    38.     GetString = RegQueryStringValue(keyhand&, strvalue)
    39.     r = RegCloseKey(keyhand&)
    40. End Function
    41.  
    42. Function StripTerminator(ByVal strString As String) As String
    43.     Dim intZeroPos As Integer
    44.  
    45.     intZeroPos = InStr(strString, Chr$(0))
    46.     If intZeroPos > 0 Then
    47.         StripTerminator = Left$(strString, intZeroPos - 1)
    48.     Else
    49.         StripTerminator = strString
    50.     End If
    51. End Function
    52.  
    53. Public Sub savestring(hkey As Long, strpath As String, strvalue As String, strdata As String)
    54.  
    55.     Dim keyhand&
    56.     r = RegCreateKey(hkey, strpath, keyhand&)
    57.     r = RegSetValueEx(keyhand&, strvalue, 0, REG_SZ, ByVal strdata, Len(strdata))
    58.     r = RegCloseKey(keyhand&)
    59.  
    60. End Sub
    61.  
    62. 'In a FORM
    63.  
    64. Private Sub Command1_Click()
    65.     'Save a Value to the Registry
    66.     savestring HKEY_CURRENT_USER, "Software\Myapp", "Te555sting", "Hello"
    67. End Sub
    68.  
    69. Private Sub Command2_Click()
    70.     'Get a value from the Registry
    71.     Retval = GetString(HKEY_CURRENT_USER, "Software\Myapp", "Te555sting")
    72.     Print Retval
    73. End Sub

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Feb 2002
    Location
    Disney Land
    Posts
    190

    .

    it doesnt work, most of the text are in red.

  8. #8
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: .

    Originally posted by 3MeMoS
    it doesnt work, most of the text are in red.
    you are probably not doing something right then... post your form...

  9. #9
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    this is megatrons code. just making it clear to him:

    PUT THIS IN A MODULE:
    VB Code:
    1. Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hkey As Long) As Long
    2. Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    3. Declare Function RegDeleteKey Lib "advapi32.dll" Alias "RegDeleteKeyA" (ByVal hkey As Long, ByVal lpSubKey As String) As Long
    4. Declare Function RegDeleteValue Lib "advapi32.dll" Alias "RegDeleteValueA" (ByVal hkey As Long, ByVal lpValueName As String) As Long
    5. Declare Function RegOpenKey Lib "advapi32.dll" Alias "RegOpenKeyA" (ByVal hkey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    6. 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
    7. 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
    8. Public Const HKEY_CLASSES_ROOT = &H80000000
    9. Public Const HKEY_CURRENT_USER = &H80000001
    10. Public Const HKEY_LOCAL_MACHINE = &H80000002
    11. Public Const HKEY_USERS = &H80000003
    12. Public Const HKEY_PERFORMANCE_DATA = &H80000004
    13. Public Const REG_SZ = 1
    14.  
    15. Function RegQueryStringValue(ByVal hkey As Long, ByVal strValueName As String)
    16.     Dim lResult As Long
    17.     Dim lValueType As Long
    18.     Dim strBuf As String
    19.     Dim lDataBufSize As Long
    20.    
    21.     On Error GoTo 0
    22.     lResult = RegQueryValueEx(hkey, strValueName, 0&, lValueType, ByVal 0&, lDataBufSize)
    23.     If lResult = ERROR_SUCCESS Then
    24.         If lValueType = REG_SZ Then
    25.             strBuf = String(lDataBufSize, " ")
    26.             lResult = RegQueryValueEx(hkey, strValueName, 0&, 0&, ByVal strBuf, lDataBufSize)
    27.             If lResult = ERROR_SUCCESS Then
    28.                 RegQueryStringValue = StripTerminator(strBuf)
    29.             End If
    30.         End If
    31.     End If
    32. End Function
    33.  
    34. Public Function GetString(hkey As Long, strpath As String, strvalue As String)
    35.     Dim keyhand&
    36.     Dim datatype&
    37.     r = RegOpenKey(hkey, strpath, keyhand&)
    38.     GetString = RegQueryStringValue(keyhand&, strvalue)
    39.     r = RegCloseKey(keyhand&)
    40. End Function
    41.  
    42. Function StripTerminator(ByVal strString As String) As String
    43.     Dim intZeroPos As Integer
    44.  
    45.     intZeroPos = InStr(strString, Chr$(0))
    46.     If intZeroPos > 0 Then
    47.         StripTerminator = Left$(strString, intZeroPos - 1)
    48.     Else
    49.         StripTerminator = strString
    50.     End If
    51. End Function
    52.  
    53. Public Sub savestring(hkey As Long, strpath As String, strvalue As String, strdata As String)
    54.  
    55.     Dim keyhand&
    56.     r = RegCreateKey(hkey, strpath, keyhand&)
    57.     r = RegSetValueEx(keyhand&, strvalue, 0, REG_SZ, ByVal strdata, Len(strdata))
    58.     r = RegCloseKey(keyhand&)
    59.  
    60. End Sub

    PUT THIS IN YOUR FORM, WITH 2 COMMAND BUTTONs (Command1, Command2)

    VB Code:
    1. Private Sub Command1_Click()
    2.     'Save a Value to the Registry
    3.     savestring HKEY_CURRENT_USER, "Software\Myapp", "Te555sting", "Hello"
    4. End Sub
    5.  
    6. Private Sub Command2_Click()
    7.     'Get a value from the Registry
    8.     Retval = GetString(HKEY_CURRENT_USER, "Software\Myapp", "Te555sting")
    9.     Print Retval
    10. End Sub
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  10. #10
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    help

    I know I'm dragging up an old thread, but I need help on this.

    I used the example buggyprogrammer posted, and I have it saving the key, but I can't get it to retrieve the key.

    It's saying "r" isn't defined, and I'm not sure what to define it as.
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

  11. #11
    Frenzied Member ober0330's Avatar
    Join Date
    Dec 2001
    Location
    OH, USA
    Posts
    1,945
    c'mon... somebody help me out here...
    format your code!! - [vbcode] [/vbcode]

    ANSWERS CAN BE FOUND HERE!!

    my personal company

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