Getting the Everyone Local Group Account Name in C#

Getting the Everyone Local Group Account Name in C#

It is quite easy to get the “Everyone” account name, with the help of the DirectorySecurity and SecurityIdentifier classes. Here is a small example of getting the name and allowing the user to save a file inside a location with the correct permissions:

string PATH = "";            if (!Directory.Exists(Path.GetFullPath(PATH)))            {                Directory.CreateDirectory(PATH);                DirectorySecurity dirSec = Directory.GetAccessControl(PATH);                SecurityIdentifier siEveryobody = new SecurityIdentifier(WellKnownSidType.WorldSid, null);                dirSec.AddAccessRule(new FileSystemAccessRule(siEveryobody, FileSystemRights.Modify | FileSystemRights.Synchronize, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow));                Directory.SetAccessControl(PATH, dirSec);            }            using (StreamWriter swWriter = new StreamWriter(PATH, true))            {                sw.WriteLine("TEXT");                sw.Flush();                sw.Close();            }

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist