PDA

View Full Version : Solved: Using the Registry in an Application



Cyberdude
11-10-2005, 12:20 PM
In J. Walkenbach's VBA book he mentions briefly that an application can use the Registry to store info. That tweaked my interest. I found several related statements in the Help, but it wasn't overly explanatory. My question is: Has anyone used the Registry to store info for an application, and what are the goods and bads about doing that?

Ken Puls
11-10-2005, 12:22 PM
Oh yes, many times!

It gives you a way of ensuring your values stay, without having to worry about hiding things in sheets, or keeping settings between sessions.

I had one app that I built where we used an Addin to import, reformat and save text files. I stored a number in the registry that incremented by one every time the procedure ran, and used that number in the file save name. I preferred doing it that way to resaving the addin all the time. It also meant that you could install it on multiple machines, and they would get their own sequence.

VBA has a GetSetting and SaveSetting function, which you can find in the help. There are also other ways to write to the registry, but with the aforementioned two, they go into a relatively safe place, although I can't remember the exact hive.

HTH,

mdmackillop
11-10-2005, 12:24 PM
Hi Sid,
http://vbaexpress.com/kb/getarticle.php?kb_id=208

Ken Puls
11-10-2005, 12:28 PM
Malcolm, that's perfect! :)

I think that there's some other registry ones in there as well.

Cyberdude
11-11-2005, 09:10 AM
Hey, Malcolm, just what I was lookiing for. Thanks, guy! :thumb

XL-Dennis
11-11-2005, 11:11 AM
Hi all,

I can agree that SaveSetting / GetSetting is easy to use but they are limit in that they can only operate with a minor part of the registry.

In addition to them there exist alternative approaches like the following example here shows: http://www.mrexcel.com/board2/viewtopic.php?t=150635&highlight=vb

If we want to fully control the registry then Windows API is the way to go:

How To Use the Registry API to Save and Retrieve Setting
http://support.microsoft.com/default.aspx?scid=kb;en-us;145679

How to write to the Windows registry by using Windows API calls
http://support.microsoft.com/default.aspx?scid=kb;en-us;135398

How To Read from the Windows Registry
http://support.microsoft.com/default.aspx?scid=kb;en-us;140170

Kind registry-regards,
Dennis

Ken Puls
11-11-2005, 05:40 PM
Best advice to go with that, though.. BE CAREFUL!

The thing I like about Get/Save setting is that they go into a place I know is benign as far as affecting other areas. You don't have that same confirmation if you start placing your own keys elsewhere, or expecially editing others.

I'm not saying don't do it, by any means. Joost will tell you that it's why I have issues with my PC since I'm rarely afraid to jump in there :p. Just be careful when you do it. Make a registry backup before you play, and remember what you did.

Cheers!

mdmackillop
11-11-2005, 05:48 PM
I'll go along with Ken on that. Although I have never had a practical need for Save/Get Settings, I would cetainly look at saving or reading data first from a text file or similar, especially in a network situation.

Cyberdude
11-11-2005, 09:34 PM
Hey, guys, a lot of great discussion on this. I've been enightened (but I still weigh the same).

XL-Dennis
11-12-2005, 04:03 AM
I usually categorize the needs for working with the registry into three groups:

User settings, which Save-/GetSetting is the simplest way to handle this kind of info.

Application settings, license and other more confidential information which Windows API is the best approach.

Installation settings, subject to which kind of application to be shipped, i e one of the above or with help of a installation software.

The above is similar for both client or serverinstallation.

Working with the registry put a high demand that we know what we are doing and in a learning process I fully agree with Ken about backup. Another option is to restore the Windows settings to a specific restore point via Windows.

Kind registry-regards,
Dennis