<p>I'm a new Windows programmer and I'm not sure where I should store user configurable application settings.  I understand the need to provide a user friendly means for the user to change application settings, like an Edit | Settings form or similar.  But where should I store the values after the user hits the Apply button on that form?  </p>

<p>What are the pros and cons of storing settings in the Windows registry vs. storing them in a local INI file or config file or similar?</p>

[{'answer_id': 6620, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 7, 'selected': True, 'text': "<p><strong>Pros of config file:</strong>  </p>\n\n<ol>\n<li>Easy to do. Don't need to know any Windows API calls. You just need to know the file I/O interface of your programming language.  </li>\n<li>Portable. If you port your application to another OS, you don't need to change your settings format.  </li>\n<li>User-editable. The user can edit the config file outside of the program executing.</li>\n</ol>\n\n<p><strong>Pros of registry:</strong>  </p>\n\n<ol>\n<li>Secure. The user can't accidentally delete the config file or corrupt the data unless he/she knows about regedit. And then the user is just asking for trouble.  </li>\n<li>I'm no expert Windows programmer, but I'm sure that using the registry makes it easier to do other Windows-specific things (user-specific settings, network administration stuff like group policy, or whatever else).</li>\n</ol>\n\n<p>If you just need a simple way to store config information, I would recommend a config file, using INI or XML as the format. I suggest using the registry only if there is something specific you want to get out of using the registry.</p>\n"}, {'answer_id': 6622, 'author': 'C. K. Young', 'author_id': 13, 'author_profile': 'https://Stackoverflow.com/users/13', 'pm_score': 2, 'selected': False, 'text': '<p>According to the documentation for <a href="http://msdn.microsoft.com/en-us/library/ms724353.aspx" rel="nofollow noreferrer">GetPrivateProfileString</a>, you should use the registry for storing initialisation information.</p>\n\n<p>However, in so saying, if you still want to use .ini files, and use the standard profile APIs (<code>GetPrivateProfileString</code>, <code>WritePrivateProfileString</code>, and the like) for accessing them, they provide built-in ways to automatically provide "virtual .ini files" backed by the registry. Win-win!</p>\n'}, {'answer_id': 6754, 'author': 'Greg', 'author_id': 108, 'author_profile': 'https://Stackoverflow.com/users/108', 'pm_score': 2, 'selected': False, 'text': '<p>There\'s a similar question <a href="http://bytes.com/forum/thread48133.html" rel="nofollow noreferrer">here</a> that covers some of the pros and cons.</p>\n\n<p>I would suggest not using the registry unless your application absolutely needs it. From my understanding, Microsoft is trying to discourage the use of the registry due to the flexibility of settings files. Also, I wouldn\'t recommend using .ini files, but instead using some of the <a href="http://msdn.microsoft.com/en-us/library/k4s6c3a0.aspx" rel="nofollow noreferrer">built-in functionality</a> to .Net for saving user/app settings.</p>\n'}, {'answer_id': 6757, 'author': 'deadtime', 'author_id': 614, 'author_profile': 'https://Stackoverflow.com/users/614', 'pm_score': 2, 'selected': False, 'text': '<p>I agree with Daniel. If it\'s a large application I think I\'d do things in the registry. If it\'s a small application and you want to have aspects of it user-configurable without making a configuration form, go for a quick INI file.</p>\n\n<p>I usually do the parsing like this (if the format in the .ini file is option = value, 1 per line, comments starting with #):</p>\n\n<pre><code>static void Parse()\n{\n    StreamReader tr = new StreamReader("config.ini");\n    string line;\n    Dictionary&lt;string, string&gt; config = new Dictionary&lt;string, string&gt;();\n\n    while ((line = tr.ReadLine()) != null)\n    {\n        // Allow for comments and empty lines.\n        if (line == "" || line.StartsWith("#"))\n            continue;\n\n        string[] kvPair = line.Split(\'=\');\n\n        // Format must be option = value.\n        if (kvPair.Length != 2)\n            continue;\n\n        // If the option already exists, it\'s overwritten.\n        config[kvPair[0].Trim()] = kvPair[1].Trim();\n    }\n}\n</code></pre>\n\n<p>Edit: Sorry, I thought you had specified the language. The implementation above is in C#.</p>\n'}, {'answer_id': 24937, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p>As Daniel indicated, storing configuration data in the registry gives you the option to use Admin Templates. That is, you can define an Admin Template, use it in a Group Policy and administer the configuration of your application network-wide. Depending on the nature of the application, this can be a big boon.</p>\n'}, {'answer_id': 25091, 'author': 'On Freund', 'author_id': 2150, 'author_profile': 'https://Stackoverflow.com/users/2150', 'pm_score': 3, 'selected': False, 'text': "<p>There's one more advantage to using an INI file over the registry which I haven't seen mentioned:\nIf the user is using some sort of volume/file based encryption, they can get the INI file to be encrypted pretty easily. With the registry it will probably be more problematic.</p>\n"}, {'answer_id': 193526, 'author': 'Lipis', 'author_id': 8418, 'author_profile': 'https://Stackoverflow.com/users/8418', 'pm_score': 5, 'selected': False, 'text': '<p>Jeff Atwood has a great <a href="http://www.codinghorror.com/blog/archives/000939.html" rel="noreferrer">article</a> about Windows\' registry and why is better to use .INI files instead.</p>\n\n<blockquote>\n  <p>My life would be a heck of a lot easier if per-application settings were stored in a place I could easily see them, manipulate them, and back them up. Like, say... in INI files.</p>\n  \n  <ul>\n  <li>The registry is a <strong>single point of failure</strong>. That\'s why every single registry editing tip you\'ll ever find starts with a big fat screaming disclaimer about how you can break your computer with regedit.</li>\n  <li>The registry is <strong>opaque and binary</strong>. As much as I dislike the angle bracket tax, at least XML config files are reasonably human-readable, and they allow as many comments as you see fit.</li>\n  <li>The registry has to be <strong>in sync with the filesystem</strong>. Delete an application without "uninstalling" it and you\'re left with stale registry cruft. Or if an app has a poorly written uninstaller. The filesystem is no longer the statement of record-- it has to be kept in sync with the registry somehow. It\'s a total violation of the DRY principle.</li>\n  <li>The registry is <strong>monolithic</strong>. Let\'s say you wanted to move an application to a different path on your machine, or even to a different machine altogether. Good luck extracting the relevant settings for that one particular application from the giant registry tarball. A given application typically has dozens of settings strewn all over the registry.</li>\n  </ul>\n</blockquote>\n'}, {'answer_id': 193570, 'author': 'Mark Ransom', 'author_id': 5987, 'author_profile': 'https://Stackoverflow.com/users/5987', 'pm_score': 1, 'selected': False, 'text': "<p>The registry is optimized for quick access and easy update, and it's the only way to do certain Windows-specific things like associating with an extension.  And you can ignore the argument about deleting a single directory to uninstall your program - Windows Vista won't let you modify files in the Program Files directory, so your config will need to go in a different folder anyway.</p>\n\n<p>There's a general guideline for Windows programming - do things the way Microsoft expects you to, and your life will be a lot easier.</p>\n\n<p>That said, I can see the appeal of the INI file, and I wouldn't blame anyone for considering it.</p>\n"}, {'answer_id': 193606, 'author': 'EvilTeach', 'author_id': 7734, 'author_profile': 'https://Stackoverflow.com/users/7734', 'pm_score': 2, 'selected': False, 'text': '<p>Use of an ini file, in the same directory as the application, makes it possible to back it up with the application. So after you reload your OS, you simply restore the application directory, and you have your configuration the way you want it.</p>\n'}, {'answer_id': 4812264, 'author': 'David', 'author_id': 342994, 'author_profile': 'https://Stackoverflow.com/users/342994', 'pm_score': 0, 'selected': False, 'text': '<p>There is one drawback to ini or config files and that is locating them if the user has the option to select where the program is installed.</p>\n'}, {'answer_id': 34921100, 'author': 'Class Skeleton', 'author_id': 3387453, 'author_profile': 'https://Stackoverflow.com/users/3387453', 'pm_score': 2, 'selected': False, 'text': '<p>The existing answers cover a lot of ground but I thought I would mention one other point.</p>\n\n<p>I use the registry to store system-wide settings.  That is, when 2 or more programs need the exact same setting.  In other words, a setting shared by several programs.</p>\n\n<p>In all other cases I use a local config file that sits either in the same path as the executable or one level down (in a Configuration directory).  The reasons are already covered in other answers (portable, can be edited with a text editor etc).</p>\n\n<p>Why put system-wide settings into the registry?  Well, I found that if a setting is shared but you use local config files you end up duplicating settings.  This may mean you end up needing to change a setting in multiple places.</p>\n\n<p>For example, say Program A and Program B both point to the same database.  You can have a "system-wide" registry setting for the connection string.  If you want to point to a different database, you can change the connection string in one place, and both programs will now run against the other database.</p>\n\n<p>Note - there is no point in using the registry in this way if two or more programs don\'t need to use the same values.  Such as, Program A and Program B both needing a database connection string that <strong><em>may</em></strong> be the same, but not always.  For example, I want Program B to now use a test database but Program A should carry on using a production database.</p>\n\n<p>With the above example, you could have some local configuration override system-wide settings but it may start getting overly complicated for simple tasks.</p>\n'}, {'answer_id': 56773065, 'author': 'Zac', 'author_id': 971443, 'author_profile': 'https://Stackoverflow.com/users/971443', 'pm_score': 0, 'selected': False, 'text': '<p>Other disadvantage of using the registry is that it is a pain if you are working in a mixed environment of 32 and 64 bit applications, as the system call for accessing the registry will <em>randomly</em>(*) add <code>\\Wow6432Node\\</code> to your registry path making you crazy while debugging.</p>\n\n<p>(*of course <strong>not</strong> randomly, but very easy to get lost)</p>\n'}, {'answer_id': 67819082, 'author': 'Doğuhan Yangöz', 'author_id': 15620042, 'author_profile': 'https://Stackoverflow.com/users/15620042', 'pm_score': 0, 'selected': False, 'text': '<p>Advantages:</p>\n<ul>\n<li>Replacement for a large number of configuration files.</li>\n<li>Common administrative functions at a central point.</li>\n<li>Almost any data can be saved by applications / drivers.</li>\n<li>In contrast to configuration files, code sequences can even be saved.</li>\n<li>Access faster than files because the database is indexed.</li>\n<li>Access can be logged using the RegMon utility</li>\n</ul>\n<p>Disadvantages:</p>\n<ul>\n<li>Difficult to work with in the absence of graphical configuration programs.</li>\n<li>Direct changes using the registry editor can create inconsistent states produce.</li>\n<li>Incomplete uninstallers leave “reminiscences” in the registry Cause problems, e.g. with a new installation.</li>\n<li>Installed applications are difficult to export to other PCs.</li>\n<li>Chronically poorly documented.</li>\n<li>Proprietary structure, therefore not suitable for standard DB access (e.g. SQL)</li>\n<li>Computer-specific, therefore not portable to other computers.</li>\n<li>Insufficient protection of the registry: depends on the configuration.</li>\n</ul>\n'}]
['https://Stackoverflow.com/questions/6607', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/27687/']