Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Home » Tip Bank » .NET » C#
Language: .NET
Expertise: Intermediate
Jul 6, 2017

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();
            }
Hannes du Preez
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date