如何在 C# 中读取 msExchMailboxSecurityDescriptor 属性

发布于 2024-12-02 07:55:58 字数 381 浏览 0 评论 0原文

我正在尝试读取 AD 中的所有用户属性。

如何在 C# 中读取 msExchMailboxSecurityDescriptor 属性?

我使用了以下代码,但出现了强制转换错误。任何建议都将受到欢迎。

  DirectoryObjectSecurity oSec = new ActiveDirectorySecurity();
  oSec.SetSecurityDescriptorBinaryForm((byte[])val);

  String m_Value = oSec.GetSecurityDescriptorSddlForm(AccessControlSections.All); 
  return m_Value; 

I am trying to read all the user attributes in AD.

How to read msExchMailboxSecurityDescriptor attribute in C# ?

I used the following code but I got a cast error. Any suggestions would be welcome.

  DirectoryObjectSecurity oSec = new ActiveDirectorySecurity();
  oSec.SetSecurityDescriptorBinaryForm((byte[])val);

  String m_Value = oSec.GetSecurityDescriptorSddlForm(AccessControlSections.All); 
  return m_Value; 

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

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

发布评论

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

评论(1

摘星┃星的人 2024-12-09 07:55:58

好的。我能够弄清楚。下面给出了代码,供感兴趣的人使用。我希望微软能够提供一些代码示例,这样人们就不必伤透脑筋了。

     SecurityDescriptor sd = (SecurityDescriptor) p_InputValue;
           AccessControlList acl = (AccessControlList)sd.DiscretionaryAcl;
              String m_Trustee = "";
              String m_AccessMask = "";
              String m_AceType = "";
              String m_ReturnValue="";

                  foreach (AccessControlEntry ace in (IEnumerable)acl)
                    {
                      m_Trustee = m_Trustee + "," + ace.Trustee;
                     m_AccessMask = m_AccessMask + "," + ace.AccessMask.ToString();
                      m_AceType = m_AceType + "," +ace.AceType.ToString();

                     }
         m_ReturnValue="Trustee: " + m_Trustee + " " + "AccessMask: " + m_AccessMask + "AceType: " + m_AceType;
         return m_ReturnValue

Ok. I was able to figure it out. The code is given below for anyone interested. I wish Microsoft had put out some code samples so that people do not have to break their heads.

     SecurityDescriptor sd = (SecurityDescriptor) p_InputValue;
           AccessControlList acl = (AccessControlList)sd.DiscretionaryAcl;
              String m_Trustee = "";
              String m_AccessMask = "";
              String m_AceType = "";
              String m_ReturnValue="";

                  foreach (AccessControlEntry ace in (IEnumerable)acl)
                    {
                      m_Trustee = m_Trustee + "," + ace.Trustee;
                     m_AccessMask = m_AccessMask + "," + ace.AccessMask.ToString();
                      m_AceType = m_AceType + "," +ace.AceType.ToString();

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