Solved

Save settings in registry

Posted on 2002-04-03
5
149 Views
Last Modified: 2010-05-02
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
Comment
Question by:b3cf
  • 3
5 Comments
 
LVL 28

Accepted Solution

by:
vinnyd79 earned 50 total points
ID: 6915475
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
 
LVL 16

Expert Comment

by:Richie_Simonetti
ID: 6915596
nice!
0
 

Author Comment

by:b3cf
ID: 6915616
Nice...very nice...very very nice...

Great thanx !
0
 

Author Comment

by:b3cf
ID: 6915804
Hi

  How can I retrieve the values ?

Thanks
0
 

Author Comment

by:b3cf
ID: 6915840
Hi

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

Thanks
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now