Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#2.0
Those interested in the why can have a look here[^].
For now, I wonder how to do the following:
 
During installation with administrative permissions, my software creates a directory within "Documents and Settings\All Users\Documents". Users shall save their projects there.
 
Normally, users are allowed to create their own files there but not to alter files created by another user. I want to allow users to change all files regardless of creator. This is what I derived from stackoverflow.com[^]
        // Create a new DirectoryInfo object.
        System.IO.DirectoryInfo dInfo = new System.IO.DirectoryInfo(dirName);
 
        // Get a DirectorySecurity object that represents the 
        // current security settings.
        DirectorySecurity dSecurity = dInfo.GetAccessControl();
 
        // Add the FileSystemAccessRule to the security settings. 
        dSecurity.AddAccessRule(
            new FileSystemAccessRule(
                new System.Security.Principal.NTAccount("UserGroupGoesHere"),
                FileSystemRights.DeleteSubdirectoriesAndFiles,
                AccessControlType.Allow
            )
        );
 
        // Set the new access settings.
        dInfo.SetAccessControl(dSecurity);
Maybe, I'll have to repeat permission adaption on every file create for the newly created file. But still the question stands: What is "UserGroupGoesHere" to substitute for? It shall represent all normal users, not excluding power users.
 
How do I get the name of the "users" user group on any given windows pc?
Posted 13-Apr-11 3:53am
lukeer15K
Comments
Manfred R. Bihy at 13-Apr-11 9:13am
   
Good question! 5+
This will most probably proove to be useful some time or the other. :)
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

I found this link on the MS support site which seems to contain relevant information: How to deal with localized and renamed user and group names[^].
 
Cheers!
 
-MRB
  Permalink  
Comments
Nishant Sivakumar at 13-Apr-11 10:08am
   
Voted 5, proposed as answer.
Manfred R. Bihy at 14-Apr-11 6:59am
   
Thanks Nishant!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

I believe the article I wrote here:
 
User Login For WinForm Applications[^]
 
will help you get the user group(s) the currently logged in user is a member of.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Right-click "My Computer", Click "Manage", then go to "Local Users and Groups", you'll see a list of Groups right there.
 
I suspect the group you want is simply called "Users".
 
Hope it helps.
  Permalink  
Comments
lukeer at 13-Apr-11 9:09am
   
I can only guess that, on an english or american windows xp, that would be the case. On my pc, it's "Benutzer".
 
But what I need is to know the correct name on any computer. I still hope there is some emumeration or method that gives the correct name of the "users" group.
Manfred R. Bihy at 13-Apr-11 9:15am
   
My guess is that it might even be the internal name as "Benutzer" and "User" are only localized descriptions off builtin accounts?
John Simmons / outlaw programmer at 13-Apr-11 10:43am
   
I think he wants to retrieve that info programatically, which is possible - I've done it.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Here is a link you may want to have a look at[^]
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

I think I found it:
    // Create a new DirectoryInfo object.
    System.IO.DirectoryInfo dInfo = new System.IO.DirectoryInfo(
        "X:\\Somewhere\\MyDirectory"
    );
 
    // Get a DirectorySecurity object that represents the 
    // current security settings.
    DirectorySecurity dSecurity = dInfo.GetAccessControl();
 
    // Add the FileSystemAccessRule to the security settings. 
    dSecurity.AddAccessRule(
        new FileSystemAccessRule(
            new System.Security.Principal.SecurityIdentifier(
                System.Security.Principal.WellKnownSidType.BuiltinUsersSid,
                null
            ),
            FileSystemRights.DeleteSubdirectoriesAndFiles,
            //FileSystemRights.FullControl,
            AccessControlType.Allow
        )
    );
 
    // Set the new access settings.
    dInfo.SetAccessControl(dSecurity);
The BuiltinUsersSid should make this work for all normal users (in some cases WorldSid could be helpful as "Everyone"). Of course, whoever executes that code has to have the right to change those permissions in order to succeed.
 
In my case I would call above code right after creating a directory. The caller would therefore be the owner. So he should be able to do whatever he wants.
 
I tried above code by creating two user accounts on my windows XP. As admin, I created a directory and run above code. Then, I created a file inside the directory.
As user1, I wasn't able to change the test file, but to delete it and create another one. As user2, I again couldn't change the new file, but delete it and create yet another one.
 
So DeleteSubdirectoriesAndFiles seems to cause just what you would expect from its name.
  Permalink  
Comments
iceboy2009d at 2-Dec-12 14:18pm
   
how to change permission of deny to allow /
These changes do not;
and i see deny in permissions advanced;
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 6

private static DirectorySecurity RemoveExplicitSecurity(DirectorySecurity directorySecurity)
{
    AuthorizationRuleCollection rules = directorySecurity.GetAccessRules(true, false, typeof(System.Security.Principal.NTAccount));
    foreach (FileSystemAccessRule rule in rules)
        directorySecurity.RemoveAccessRule(rule);
    return directorySecurity;
}
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Maciej Los 310
1 OriginalGriff 285
2 Afzaal Ahmad Zeeshan 200
3 Sergey Alexandrovich Kryukov 195
4 BillWoodruff 180
0 OriginalGriff 6,499
1 Sergey Alexandrovich Kryukov 6,048
2 DamithSL 5,193
3 Manas Bhardwaj 4,657
4 Maciej Los 4,120


Advertise | Privacy | Mobile
Web02 | 2.8.1411022.1 | Last Updated 2 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100