Solved

Save settings in registry

Posted on 2002-04-03
5
151 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

809 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