Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get list of groups-users-permissions-special permission for a folder in Windows 2003, programatically

I use Window 2003 server, and I need get information about security folder, programatically using C#.

I want create a tool for check permissions. I need get the groups, users, permissions and special permissions for a folder,

C:\Documents and Settings\All Users\Application Data\Microsoft\Crypto\RSA\MachineKeys

edit:

the following is a sample code for the GetSecurityDescriptorSddlForm method.

public static string GetObjectPermission(string fullFolderName)
{
    FileSecurity fileSecure = File.GetAccessControl(fullFolderName);
    StringBuilder acer = new StringBuilder();
    fileSecure.GetSecurityDescriptorSddlForm(AccessControlSections.All);

    foreach (FileSystemAccessRule ace in fileSecure.GetAccessRules(true, true, typeof(NTAccount)))
    {
        acer.Append(ace.FileSystemRights + ":" + ' ' + ace.IdentityReference.Value + "\n");
    }
    return acer.ToString();
}

This sample code will show you which NTAccount can modify or read the folder, such as this function.

How can I get groups and special permissions ??

Any sample code, suggestions?

like image 865
Kiquenet Avatar asked Oct 11 '10 11:10

Kiquenet


People also ask

How do I check group permissions in Windows?

Click Start > Control Panel > Administrative Tools > Local Security Policy. In the Local Security Settings window, expand Local Policies > User Rights Assignment to display the policies.

How do I see what folders an ad group has access to?

Open Windows Explorer, and then locate the file or folder for which you want to view effective permissions. Right-click the file or folder, click Properties, and then click the Security tab. Click Advanced, click the Effective Permissions tab, and then click Select.

How do I get special permissions in Windows 11?

In Windows 11, use the Privacy page to choose which apps can use a particular feature. Select Start > Settings > Privacy & security. Select an App permission (for example, Location) then choose which apps can access it.


1 Answers

Could you use DirectoryInfo to get the ACL's? All ACL's should be in there (user, group):

        // Create a new DirectoryInfo object.
        DirectoryInfo dInfo = new DirectoryInfo(FileName);

        // Get a DirectorySecurity object that represents the  
        // current security settings.
        DirectorySecurity dSecurity = dInfo.GetAccessControl();

Full docs: http://msdn.microsoft.com/en-us/library/c1f66bc2(v=vs.110).aspx

like image 98
Bill Sambrone Avatar answered Sep 30 '22 00:09

Bill Sambrone