devxlogo

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();            }

Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.

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.