Solved

Save settings in registry

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…

820 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