Solved

how to change file permissions in a .NET 4.0 Setup project

Posted on 2010-08-30
3
481 Views
Last Modified: 2012-05-10
Hello Experts,

I have a setup projects that installs a winForms applications on the users machine. The user has an option to save some defaults in the .config file for the application, but when they try it throws "Access to the path is denied." When I look the folder is "Read".  I can change this manually, but that still doesn't fix the issue. How can I assign the appropriate permissions during my installation to let user update the .config file?
0
Comment
Question by:MDKDevelopers
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 6

Accepted Solution

by:
MikeQc earned 500 total points
ID: 33563310
It's probably because your application is installed under the "Program Files" folder.
Application settings should normally be changed only by administrators.
By default, regular users does not have access to "Program Files" and his children.

So, that said, if you want to give access to only a specific file in read/write for everyone, you should use this code in your installer:

            string filename = @"C:\Program Files\Your App Folder\Your App.exe.config";  // <-- Change with the correct .config file
            // This will retreive the "Everyone" string depending of your OS version
            SecurityIdentifier sid = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
            NTAccount acct = sid.Translate(typeof(NTAccount)) as NTAccount;
            string strEveryoneAccount = acct.ToString();
            // Get the current Access Control settings for your file
            FileSecurity filesec = File.GetAccessControl(filename);
            // Add "Everyone" with the "Modify" right
            filesec.AddAccessRule(new FileSystemAccessRule(strEveryoneAccount, FileSystemRights.Modify, AccessControlType.Allow));
            File.SetAccessControl(filename, filesec);

Open in new window

0
 
LVL 6

Expert Comment

by:MikeQc
ID: 33563315
-> By default, regular users does not have access to "Program Files" and his children.

I mean does not have "modification" access to "Program Files"...
0
 

Author Closing Comment

by:MDKDevelopers
ID: 33566378
I did not get to try out the solution because we opted to go with Click Once deployment. I want to award you the pionts since I believe it's only fair to do so.
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question