Solved

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

Posted on 2010-08-30
3
480 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Suggested Solutions

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

732 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