Click here to Skip to main content
15,882,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I'm writing a Windows application using .NET (C#). This application needs to have a file in which settings are stored. These settings are to do with which features of the application have been unlocked, and are hence editable at run-time. I don't want the settings to be user-dependent, as I want the features to be available to all users of the computer, not just the user that unlocked them.

I'd like the settings file to be installed at deploy-time (using the setup project available in Visual Studio), and then accessible (with read/write permissions) to all users at run-time.

Does anyone have any suggestions how this can be done, and in such a way that it will work on all newer versions of Windows (XP/Vista/7)? I'd also like to adhere to recommended security practices, in that the application should run fine under normal user permissions (although it will need to be deployed under administrator permissions).

Thanks in advance for your help/suggestions,

Steve.

P.S. Thoughts I've had so far:

I've noticed that the setup project exposes the a " Common Files Folder" "special folder" which could be of use to me, although this deploys to 'C:\Program Files\Common Files' which doesn't have write permissions for all users.

I've also noticed that .NET exposes the following enum item available in C#: Environment.SpecialFolder.CommonApplicationData. This sounds perfect, but I'm not sure how to access this using the setup project? Will this folder provide the permissions I need?

Is there some way I can add user write permissions to a folder (or a sub-folder I create) at deploy-time? Instead, should I be looking at using a registry key to hold the text I intended on storing in the settings/ini file?
Posted

This is how I do it:

public static System.Environment.SpecialFolder m_specialFolder = Environment.SpecialFolder.CommonApplicationData;
 
Share this answer
 
Thanks for your help John.

I know how to do what I need on the C# side. It's more the installer I was struggling with. I wasn't sure how to create a default file in the location that CommonApplicationData points at. However, I've circumvented this problem now by getting my application to generate a new file if one is not found, hence removing the need to deploy a default file.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900