• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 163
  • Last Modified:

Save settings in registry

Hi

  Could someone advice me on how I could save settings to the registry.
Right now it saves under HKEY_CURRENT_USER -> Software -> VB and VBA Program Settings. But I want it to be under HKEY_CURRENT_USER -> Software -> Test1 -> Test2.

Any help is greatly appreciated.

Thanx
0
b3cf
Asked:
b3cf
  • 3
1 Solution
 
vinnyd79Commented:
Option Explicit
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 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
Private Const HKEY_CURRENT_USER = &H80000001
Private Const ERROR_SUCCESS = 0&
Private Const REG_SZ = 1
Private X As Long
Private Sub SaveString(Hkey As Long, strpath As String, strValue As String, strdata As String)
    Dim keyhand As Long
    Dim r As Long
    X = RegCreateKey(Hkey, strpath, keyhand)
    X = RegSetValueEx(keyhand, strValue, 0, REG_SZ, ByVal strdata, Len(strdata))
    X = RegCloseKey(keyhand)
End Sub

Private Sub Command1_Click()
Call SaveString(HKEY_CURRENT_USER, "Software\Test1", "Test2", "")
End Sub
0
 
Richie_SimonettiIT OperationsCommented:
nice!
0
 
b3cfAuthor Commented:
Nice...very nice...very very nice...

Great thanx !
0
 
b3cfAuthor Commented:
Hi

  How can I retrieve the values ?

Thanks
0
 
b3cfAuthor Commented:
Hi

  How could I store a null string into a reg. value ?

Thanks
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now