Solved

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

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Flash (http://en.wikipedia.org/wiki/Adobe_Flash) has evolved over the years to where it has become a masterful tool for displaying content screen.  It has excellent layout placement, UI precision as well as rendering capabilities. This, along with t…
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

773 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