Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where should I store application specific settings?

I've been asked to update a VB6 application that's been running on WinXP for the last 6 years. The client wants to use Windows 7. Up until now, the app stored its settings in an INI file located in the application directory. One key difference between XP and 7 is that you can't write to C:\Program Files\AppFolder anymore.

I am trying to figure out where on the file system should I store settings? Given that the application is still required to run on WinXP, I am kind of confused.

On WinXP, I have the following:

C:\Documents and Settings\profilename\Application Data
C:\Documents and Settings\profilename\Local Settings\Application Data

On Windows 7, I have the following:

C:\Users\profilename\AppData\Local
C:\Users\profilename\AppData\LocalLow
C:\Users\profilename\AppData\Roaming

Each one of these folders have subfolders that seem to store settings/files for various products

So 2 questions:

  1. Given all these folders, where do I store my settings?
  2. I am assuming that there is a nifty Windows API call that would give me the proper location of this folder. And I am hoping it works on both XP and 7. Is my assumption correct? If so, a link would be much appreciated.
like image 293
AngryHacker Avatar asked Nov 25 '10 03:11

AngryHacker


People also ask

Where are application settings stored?

These config files are typically placed under separate root directory than the rest of application code. For example, in case of Java they are typically under src/main/resources .

Where are .NET application settings stored?

Settings. settings is located in the My Project folder for Visual Basic projects and in the Properties folder for Visual C# projects. The Project Designer then searches for other settings files in the project's root folder. Therefore, you should put your custom settings file there.

What are application settings?

Application settings enables developers to save state in their application using very little custom code, and is a replacement for dynamic properties in previous versions of the . NET Framework.


1 Answers

There are a number of special folders you can use, on XP/Vista/Windows 7:

  • The CSIDL_APPDATA folder is the one you will likely be most interested in. Data stored here is available to roaming users at whatever machine they log in to. This is the best place to store simple configuration data. All users have write access to this (and the last) folder. Note that none of the above folders are for user-generated data! That would properly belong under the My Documents hierarchy.
  • EDIT: As Cody Gray suggests in the comments, also consider CSIDL_LOCAL_APPDATA for application data that will always be local to the current machine, but is set aside on a per user basis. The data in this folder is not available on a roaming basis, so it should be data that the user will likely not miss if they log in to a different machine.

I shamelessly copied the explanation above from a good article by Karl Peterson, explaining this for VB6 programmers. Karl also has a ready-to-use class that will help you find the directories, but IMHO he's overcomplicated things this time. Bob Riemersma has a better way in one line, using the Shell object, as below. EDIT Bob's comment below explains why it's best to use late binding for this rather than early binding.

Const ssfCOMMONAPPDATA = &H23 
Const ssfLOCALAPPDATA = &H1c
Const ssfAPPDATA = &H1a
Dim strAppData As String 

strAppData = _ 
    CreateObject("Shell.Application").NameSpace(ssfAPPDATA).Self.Path 

In my opinion it's fine to continue to use INI files in these directories.

like image 137
MarkJ Avatar answered Sep 30 '22 16:09

MarkJ