Windows Registry VB6

From Free Knowledge Base- The DUCK Project: information for everyone
Revision as of 08:19, 2 February 2008 by Admin (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

You can read from and write to the Windows Registry with your Visual BASIC program. There are basically two main approaches to accomplishing this in your Visual BASIC program.

  • Using Visual BASIC Built in Registry Functions
  • Advanced Windows 32 Base API DLL (advapi32.dll)

What's the difference?

Using built in registry functions limits you a great deal. Using the API allows you complete access to the registry from an application level. Using the built in functions is quick and easy. Using the API requires a bit more work and external function calls. Using the built in functions is safer.

Visual BASIC Built In Registry Functions

The functions are :

  • GetSetting
  • SaveSetting

SaveSetting stores the data in the Registry (in HKEY_CURRENT_USER|Software|VB and VBA Program Settings|YourAppName). The four parts of the function are the name under which it is stored. That is the main limitation, being where the data is stored. All of your registry data for your application has to be under "VB and VBA Program Settings" under the HKEY_CURRENT_USER hive.

Parameters

  • AppName: Required. String expression containing the name of the application or project to which the setting applies.
  • Section: Required. String expression containing the name of the section in which the key setting is being saved.
  • Key: Required. String expression containing the name of the key setting being saved.
  • Setting: Required. Expression containing the value to which Key is being set.

The SaveSetting function adds the key to HKEY_CURRENT_USER\Software\VB and VBA Program Settings. SaveSetting requires that a user be logged on since it operates under the HKEY_LOCAL_USER registry key, which is not active until a user logs on interactively.

HKEY_CURRENT_USER\Software\VB and VBA