
-----------------------------------
Ashi_Mashi2
Thu Mar 17, 2005 7:27 pm

How to add Registry values in VB?
-----------------------------------
Hi, I am new to visual basic, and i need to add a registry value to the 'HKEY_LOCAL_USER..." how do you do it? i scanned through many websites, but they were too professional....if you could please explain it very basic to me...thanks...

-----------------------------------
Tony
Thu Mar 17, 2005 9:34 pm


-----------------------------------
if you're new to a language, you shouldn't be messing with registry values right away. Play with some buttons first, get to know what you're doing.

-----------------------------------
Brightguy
Fri Mar 18, 2005 8:54 pm

Re: How to add Registry values in VB?
-----------------------------------
Yeah, Tony's right... but if you just want your application to store a few values...
SaveSetting appname, section, key, setting
This will create a string value in HKEY_CURRENT_USER\Software\VB and VBA Program Settings\appname\section.  It's more complicated if you want to save somewhere else, or to something other than a string. (Use Win API functions.)

-----------------------------------
Ashi_Mashi2
Sun Mar 20, 2005 7:19 pm


-----------------------------------
thanks guys....i told you i'm new, but not that new :wink: ....lol....anyway, i found a way to do it :D ...I still dont quiet understand what it is doing (cause i got the code from another website) but, it works anyway...


Public Function CreateRegKey(sPath As String, Optional lKey As HKEYS = HKEY_LOCAL_MACHINE) As Long

    Dim hNewKey As Long         'handle to the new key
    Dim lRetVal As Long         'result of the RegCreateKeyEx function
    Dim lRetVal2 As Long         'result of the RegCreateKeyEx function
        
    ' if the path has a leading "\" strip it
    FixPath sPath
    lRetVal = RegCreateKeyEx(lKey, sPath, 0&, vbNullString, REG_OPTION_NON_VOLATILE, _
                                KEY_ALL_ACCESS, 0&, hNewKey, lRetVal2)
    If lRetVal  ERROR_SUCCESS Then
        lRetVal = lRetVal + ERROR_OFFSET
        CreateRegKey = lRetVal
    Else
        CreateRegKey = 0
        RegCloseKey hNewKey
    End If
End Function


-----------------------------------
betaflye
Wed Apr 20, 2005 6:28 pm


-----------------------------------
It's basically an API call, if you want more goodies like that just install MSDN library.
