1

Here is my scenario,

I have an Outlook add-in which, I am writing some information into a common file through this Add-In. When I created a installable, I kept common file under "All Users"(Common Application Data Folder) folder. When I install this add-in on XP it is working perfectly fine and no issue of permission.

Now, when i move this application to Windows 7, I am getting some file access permission exception. With reference to some blogs, I have added application specific folder under "All Users." After this also I am unable to write into this file.

Is there anything else that I need to do, by which I will able to write into this file.

I have read some blogs about UAC, however, I didn't get clear picture of its use for Add-in.

Sameera Thilakasiri
  • 9,452
  • 10
  • 51
  • 86
Avi Kenjale
  • 2,414
  • 6
  • 29
  • 46

2 Answers2

1

By default, standard users don't have write access to the common app data folder. If you wish to allow your users to write there you should create a sub-folder and apply an appropriate ACL. Do this as part of your installation because that's when you have sufficient rights to create the ACL.

Another option is to store these settings on a per-user basis and thereby avoid the issues with security.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • Thank you for your response. I have already created application specific sub folder under "Common Application Data Folder", however I am not aware with ACL with installation. Is there any specific reference, by which I can come over this situation? – Avi Kenjale Dec 05 '11 at 06:10
  • Your setup tool will be able to apply security settings, i.e. ACLs. – David Heffernan Dec 05 '11 at 06:14
  • I have checked, however, I am unable to get those. I am using VSTO 2010. I will appreciate your detail description if any. – Avi Kenjale Dec 05 '11 at 06:30
  • what tool do you use to create your install program? – David Heffernan Dec 05 '11 at 06:36
  • I am using visual studio's setup project template? – Avi Kenjale Dec 05 '11 at 06:38
  • I'm not familiar with that tool. This is now veering away from the original question. – David Heffernan Dec 05 '11 at 06:47
  • Sorry for it. My actual question was, how could I mange ACL in Windows 7, to provide write permission to specific file which is under "Common application data folder"? – Avi Kenjale Dec 05 '11 at 07:02
  • That's your question now. But it's not the question asked. If you want more help on this problem you need to ask specifics about your setup tool. I answered the question you asked. – David Heffernan Dec 05 '11 at 07:18
0

To add specific permissions to files, I use a helper extension function I created for this: (You need the right privs to do this on a file)

public static void AddAccessEveryone(this FileInfo file, FileSystemRights rights, AccessControlType accessType)
{
    FileSecurity access = file.GetAccessControl();
    SecurityIdentifier everyone = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
    access.AddAccessRule(new FileSystemAccessRule(everyone, rights, accessType));
    file.SetAccessControl(access);
}

You call it like this:

file.AddAccessEveryone(FileSystemRights.Read | FileSystemRights.Write, AccessControlType.Allow);

You have to add the reference System.ServiceModel to your project. You must also call it after the file has been created, it doesn't do any good to call it before then.

Chuck Savage
  • 11,775
  • 6
  • 49
  • 69