?
Solved

C# windows forms app change permissions on MDB file

Posted on 2011-02-25
5
Medium Priority
?
1,076 Views
Last Modified: 2012-05-11
I have a windows application written in C#. I use InstallAware as the packager and all seems to go well on install. I have an access database file as the data store of the application which is stored in the Program Data section of the users machine which allows full write capabilities etc. My problem is that i cannot get the permissions i apply to the file to stay after the install.

Once installed, the program auto-starts and queries user for info which is written to the application no problem. The Security permissions on the file are set to Full Control for everyone on install correctly. The problem happens once the application is closed and restarted. The database file then has the permissions stripped to only read & execute and read for the Users group.

I have to physically go in and add the write permission and all runs fine after that but i do not want to have end users doing this.

Can someone help me with code to assign permissions to all users or users for at LEAST read/write?

Thanks in advance!

Cheers
0
Comment
Question by:Halon
[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
5 Comments
 
LVL 9

Accepted Solution

by:
rawinnlnx9 earned 1000 total points
ID: 34981530
This post here explains exactly how to do this. Please read the reply that is Green as it is the answer:

http://social.msdn.microsoft.com/Forums/eu/windowssdk/thread/de213b61-dc7e-4f33-acdb-893aa96837fa
0
 
LVL 8

Assisted Solution

by:davesgonebananas
davesgonebananas earned 1000 total points
ID: 34981678
The ProgramData or CommonApplicationData special folder is used for system wide application specific data and AFAIK normal users have read permissions to this folder by default.

You can change permissions using ICACLS or in C# using the code below:
http://www.codeproject.com/tips/61987/Allow-write-modify-access-to-CommonApplicationData.aspx
0
 
LVL 33

Expert Comment

by:Todd Gerbert
ID: 34982392
I would guess that your MDB's access control list may contain Everyone:FullControl, but does not specify to ignore inherited permissions.  Or, your application is deleting & recreating the file - in which case the new one would inherit permissions from the containing folder.

I'm not familiar with InstallAware - how are you setting the permissions at install?
0
 

Author Closing Comment

by:Halon
ID: 34983512
Used a combination of code form your posts. Thanks for the help. Below is the code i used if anyone else is stuck on this
0
 

Author Comment

by:Halon
ID: 34983527
 
private void Whatever(){
//grab the currently logged in user
string nametext = WindowsIdentity.GetCurrent().Name;

AddDirectorySecurity(DBFile, @nametext, FileSystemRights.ReadAndExecute, AccessControlType.Allow);
 AddDirectorySecurity(DBFile, @nametext, FileSystemRights.Write, AccessControlType.Allow);
}

 // Adds an ACL entry on the specified directory for the specified account.
        public static void AddDirectorySecurity(string FileName, string Account, FileSystemRights Rights, AccessControlType ControlType)
        {
            // Create a new DirectoryInfo object.
            DirectoryInfo dInfo = new DirectoryInfo(FileName);

            // Get a DirectorySecurity object that represents the 
            // current security settings.
            DirectorySecurity dSecurity = dInfo.GetAccessControl();

            // Add the FileSystemAccessRule to the security settings. 
            dSecurity.AddAccessRule(new FileSystemAccessRule(Account,
                                                            Rights,
                                                            ControlType));

            // Set the new access settings.
            dInfo.SetAccessControl(dSecurity);

        }

Open in new window

0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Suggested Courses

770 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