Visual Basic Source Code - Read the Registry

For: VB4, VB5, VB6

Visual Basic, by default using GetSetting and SaveSetting allows reading and writing only to the VB and VBA Programs key under HKEY_Current_User\Software. There can be any number of reasons to want to read or write other portions of the registry, and that can be accomplished using API calls. There are two typical ways that this is done; the first is with a Class Module, and the second is with a regular function. I personally prefer the function approach, which is shown in the code below. My earliest versions of this function were published on Compuserve in 1996, and have evolved steadily since then.

With this code, you can read any portion of the registry for which you have permissions. Write functions are on another page (link at bottom). First you need a number of declares. Not all of these are used for every registry access, but it will not hurt to include them in the declarations portion of the .BAS module that contains your function. Copy/Paste from the box below:



Now we are ready for the function itself. This function will get string (REG_SZ) or numerical (REG_DWORD) values, but will always return them as strings.


Go to the VB Source Code index or Go to the Registry Write Code

Comments? Send mail to donb@arcatapet.net
Snail Mail: Arcata Pet, 600 F Street, Arcata, CA 95521-6301 USA
Webspace provided by and ©Copyright 1994-2013 by Arcata Pet Supplies. All Rights Reserved.