A writable folder by all users on one computer

I have a .NET WPF application on my desktop that uses an embedded database (SQLite). Where to put the database file? This is the same database for all users.

I tried to use CommonAppData but was not writable by non-admin users. So I tried to use a custom installer action to grant write access to all users of that folder, but that fails on domain computers. The code:

string path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "MyAppName");

DirectorySecurity security = Directory.GetAccessControl(appDataPath);
FileSystemAccessRule rule = new FileSystemAccessRule("Users", FileSystemRights.WriteData, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.InheritOnly, AccessControlType.Allow);
security.AddAccessRule(rule);   
Directory.SetAccessControl(appDataPath, security);

      

Will the ". \ Users" insead "Users" work in the domain?

Is this the best approach? Is there another folder that I could use?

+2


a source to share


1 answer


By default, you cannot use a folder. You need to configure the directory's ACL, otherwise the default right will include read access for users other than Owner (creator) files.

Typically, you have all rights to the directories you create, so my approach was to create an application subdirectory in the ProgramData folder, and then, as the owner (via creation) of the new object, I had full control over that and could add my full access to full access as an inherited access control entry for that.



I also ran into problems with "users" using the Windows API and had to switch to using the known sid. Tested on German system, at least the "Users" line was completely different.

+2


a source







All Articles