以编程方式获取 Windows 2003 中文件夹的组-用户-权限-特殊权限列表

发布于 2024-09-27 06:45:49 字数 882 浏览 2 评论 0原文

我使用 Window 2003 服务器,我需要使用 C# 以编程方式获取有关安全文件夹的信息。

我想创建一个检查权限的工具。我需要获取文件夹的组、用户、权限和特殊权限,

C:\Documents and Settings\All 用户\应用程序 数据\Microsoft\Crypto\RSA\MachineKeys

编辑:

以下是 GetSecurityDescriptorSddlForm 方法的示例代码。

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

此示例代码将向您展示哪些 NTAccount 可以修改或读取文件夹,例如此功能。

我怎样才能获得组和特殊权限?

有示例代码、建议吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

夜夜流光相皎洁 2024-10-04 06:45:49

您可以使用 DirectoryInfo 来获取 ACL 吗?所有 ACL 都应该在那里(用户、组):

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

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

完整文档:
http://msdn.microsoft.com/en -us/library/c1f66bc2(v=vs.110).aspx

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

尤怨 2024-10-04 06:45:49

如果您想获取文件夹上 ACL 中的所有 ace 列表,您应该使用此方法,也可以使用此方法访问其他 ace 属性,例如
ace.AccessControlTypeace.IsInherited

 public static void checkAceInformation(string fileName,string loginName)
        {
            string fileSystemRightsValue = "";

            FileSecurity security = File.GetAccessControl(FileName);

            AuthorizationRuleCollection acl = security.GetAccessRules(true, true, typeof(System.Security.Principal.NTAccount));

            foreach(FileSystemAccessRule ace in acl)
            {
                if(ace.IdentityReference.Value == LoginName)
                {
                    fileSystemRightsValue = ace.FileSystemRights.ToString();

                    Console.WriteLine(LoginName +  "  your permission value is" + fileSystemRightsValue)

                    return;
                }
            }
            Console.WriteLine(LoginName + "your not permission in this folder");

        }

If you want to get all ace list in ACL on folder,you should use this method, also with this method you can access other ace properties, like
ace.AccessControlType , ace.IsInherited;

 public static void checkAceInformation(string fileName,string loginName)
        {
            string fileSystemRightsValue = "";

            FileSecurity security = File.GetAccessControl(FileName);

            AuthorizationRuleCollection acl = security.GetAccessRules(true, true, typeof(System.Security.Principal.NTAccount));

            foreach(FileSystemAccessRule ace in acl)
            {
                if(ace.IdentityReference.Value == LoginName)
                {
                    fileSystemRightsValue = ace.FileSystemRights.ToString();

                    Console.WriteLine(LoginName +  "  your permission value is" + fileSystemRightsValue)

                    return;
                }
            }
            Console.WriteLine(LoginName + "your not permission in this folder");

        }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文