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?
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.
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With