Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I set a file to be writeable by all users?

I want to set a file to be writeable by all users.

FileSecurity sec = File.GetAccessControl(fileName);

string users = ?????;
sec.AddAccessRule(new FileSystemAccessRule(
        users,
        FileSystemRights.Write, 
        AccessControlType.Allow));

File.SetAccessControl(fileName, sec);

The problem is that I don't know which string to use. I have tried users = WindowsAccountType.Normal.ToString(), but that only gives "Normal", which doesn't work. How can I get the string that designates the group of all users on a machine?

like image 689
Boris Avatar asked Sep 16 '11 12:09

Boris


People also ask

How do I change permissions for a file to be readable for everyone?

Change file permissions To change file and directory permissions, use the command chmod (change mode). The owner of a file can change the permissions for user ( u ), group ( g ), or others ( o ) by adding ( + ) or subtracting ( - ) the read, write, and execute permissions.

How do I give full permission using chmod?

To give the owner all permissions and world execute you would type chmod 701 [filename]. To give the owner all permissions and world read and execute you would type chmod 705 [filename].


1 Answers

I assume you are looking for the "Everyone" group which all logged-on users belong to. However using the string "Everyone" will get you into serious trouble on non-english systems

A much better solution is to use it via SecurityIdentifier WellKnownSidType.WorldSid:

SecurityIdentifier everyone = new SecurityIdentifier(WellKnownSidType.WorldSid, null);

The complete solution is already described in this answer: Add "Everyone" privilege to folder using C#.NET

like image 168
Robert Avatar answered Sep 22 '22 14:09

Robert