I want to save the configuration of my project which includes

  1. Screen size
  2. Screen position
  3. Folder paths
  4. Users settings and so on.

The standard places where you can save these are configuration values are:

  1. Registry
  2. INI files
  3. Personal files (like *.cfg)

How do you choose between these places? Also, are there any pros and cons of using any of them?

  • 2
    What tools are you using? Some technologies comes with pretty nice build in configuration management tools. – user2567 Apr 13 '12 at 7:17
  • @Pierre303 currently using VS 2008 for VC++ – Shirish11 Apr 13 '12 at 7:41
  • Will users need to make changes? – JeffO Apr 13 '12 at 15:03
  • 1
    Have you considered YAML, you get the best of both, ini and xml en.wikipedia.org/wiki/YAML – JF Dion Apr 13 '12 at 15:43

Also are there any pros and cons of using any of them?


  • + Relatively standard in the Windows environment.
  • + Generally good support from installers, etc.
  • - Platform specific API, if you ever want to port your application.
  • - Not particularly human readable.

INI Files:

  • + Simple format.
  • + Portable.
  • + Human readable.
  • - May be difficult to store more complex information (for example, anything nested more than two levels deep).
  • ? May have to write your own parser (although not difficult) or use an external library like SimpleIni (thanks to Jonathan Merlet for the comment).

XML Files (I'm guessing this is the .cfg option):

  • + A standard format.
  • + Portable.
  • + Supports deeply nested structures.
  • - Not particularly human readable.

Personally, for Windows applications I tend to use C#, and go with a personal file for the user, stored as XML. I do this typically because human readability is not usually a priority in the types of applications I write (and the application should have a configuration editor, in any case), and in the .NET environment, it's very easy to work with XML. I very often end up with a UserConfiguration object which simply gets serialised to and from a configuration file - almost no development involved (parsing, casting stuff around), and you have your configuration ready to use in a strongly typed environment.

  • I used SimpleIni for parsing INI files a while ago and it was working nicely. – Jonathan Merlet Apr 16 '12 at 13:16
  • @JonathanMerlet thanks, I've added SimpleIni to the post. – Daniel B Apr 16 '12 at 13:56

I'd go with INI files, they are the more human friendly option:

width       = 600
height      = 350
position.x  = 400
position.y  = 200

path1       = "/some/random/path/"
path2       = "/some/other/random/path/"

name        = "Yannis"
preference  = "INI"

XML might be a good option, but it can't beat INIs' simplicity and elegance:

<?xml version="1.0" encoding="utf-8" ?>

INIs are also very well understood and platform independent. There aren't probably as many tools available for them as for XML files, because, well, who needs a specialized tool to read and edit an INI file?

  • 2
    Funny, but I find the XML nicer looking and easier to read. For those that don't like the verbosity, JSON is a suitable alternative. – Robert Harvey Apr 13 '12 at 15:38
  • 3
    @RobertHarvey JSON I like (and would use if I needed deeper nesting), but XML is really not my cup of tea... – yannis Apr 13 '12 at 15:57
  • 2
    XML can be made nicer by rolling values into attributes. For example, <window width="600" height="350" /> – Robert Harvey Apr 13 '12 at 16:01
  • I'm actually surprised nobody's mentioned YAML yet. I feel it's a touch more human friendly than JSON, but quite similar in capability and syntax. The yaml.org website probably scares away anyone not already familiar with it though. – Daniel B Apr 16 '12 at 5:29
  • @DanielB Someone did mention YAML ;) – yannis Apr 16 '12 at 5:34

My preference is XML files. They are hierarchical, you can bend them to your will in almost any way imaginable, they are well understood, platform independent, and there is a wide array of software available to read and write them.

  • 6
    But horribly verbose and tend to be not human-readable afterall (think not indented or bloated to the max with namespace declarations and other bs). – Manjabes Apr 13 '12 at 8:47
  • 1
    @Manjabes: Characteristics which are unlikely to be significant for configuration files. – Robert Harvey Apr 13 '12 at 15:22
  • @robert harvey : very significant where I live. For the basic meddling with settings you use the gui, for the advanced settings you go edit the ini. – Pieter B Apr 16 '12 at 14:07

To expand Jeff D's suggestion of YAML, here's a brief intro.

YAML is similar to JSON (in fact, JSON is a subset of YAML since version 1.2 of the YAML standard, and can thus valid JSON can be parsed by YAML parsers). At first glance, the main difference being that YAML (by default) uses indentation rather than bracketing to show hierarchy. There is also a noticable lack of quotes for strings. A quick example from above:

    width:       600
    height:      350
      x:         400
      y:         200
    path1:       some/random/path
    path2:       some/other/random/path
    name:        Joe Soap
    preference:  YAML

See Wikipedia's YAML page for better examples. Support for YAML exists for most major languages (see yaml.org for details).


You forgot an option: the Database. This is mostly used in scenarios where you have users logging into your application when your application can't rely on the logged in windows user. This is for instance when your app is running in a kiosk mode windows.

  • You may need an INI file or registry key to hold the connection details/string to the database – Class Skeleton Jan 21 '16 at 10:00
  • @CamelCase Inifile or registry key was already mentioned in the Question, but not Database. I didn't mean to say that you can't use multiple methods at the same time. – Pieter B Jan 21 '16 at 10:34

My personal preference is XML files:

In most cases I don't expect the user to have to edit their configuration settings so the human readability issue is not an argument in this case.

If they do need to edit them you can provide a editing tool - this prevents the user doing something daft with the data. If they want to restore the default settings you can just tell them to delete file x which most users will be comfortable doing.

Note that you still need to be careful that you have permission to store your file as some locations do not have write access by default in Windows 7 etc.

INI Files are a good standard way of storing configuration and are tried and tested but they just feel a bit 'Windows 3.1' to me!

Probably the best option if you want the user to be able to tinker with their data

I would personally steer away from the registry. For one thing you cannot guarantee that the user has the necessary permissions to read/write to wherever you want to store your data.

In more recent OSs where registry virtualisation comes into play this can cause major confusion because you can't 'see' the virtualised settings - this has bitten us more than once where have spent hours trying to figure out why something was not working.

  • 3
    If you're worried about Permissions for registry locations, then you're probably trying to store them in the wrong place. The user should have permissions to the HKey_Current_User hive, and that's where per-user settings should be! – Neil White Apr 13 '12 at 16:51
  • @NeilWhite - agreed they should have permissions but an over zealous IT administrator can change this (or give read/write but not create permissions). Also the OP did not mention that these settings were necessarily per user, they may be per machine. – Matt Wilko Apr 16 '12 at 7:52
  • Also, registry can have size limit. Files don't. – linquize Apr 16 '13 at 6:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.