选中/取消选中 C# 活动目录特定单选按钮

本文关键字:单选按钮 活动 取消 选中 | 更新日期: 2023-09-27 18:36:47

有人可以帮助我解决以下问题吗?

我想查看活动目录中的特定单选按钮是否被选中或取消选中。在下面,您有一个指向单选按钮的打印屏幕的链接(标记为红色)

http://media.ipsosinteractive.com/projects/S1027838/img/pic.jpg

谢谢!

乐:

我正在使用系统目录服务;

如果我可以使用System.DirectoryServices.AccountManagement连接到AD,那将容易得多。

我不知道如何连接...

假设我有域:Office.company.intra

PrincipalContext

domainContext = new PrincipalContext(ContextType.Domain, "...", "DC=..,DC=..,DC=..", systemAccount, systemAccountPassword);

LEE - 供将来参考 AD 示例:

string acc="";
        if (rs.GetDirectoryEntry().Properties["samaccountname"].Value != null)
            Label20.Text = rs.GetDirectoryEntry().Properties["samaccountname"].Value.ToString();
        if (rs.GetDirectoryEntry().Properties["givenName"].Value != null)
            Label21.Text = rs.GetDirectoryEntry().Properties["givenName"].Value.ToString();
        if (rs.GetDirectoryEntry().Properties["sn"].Value != null)
            Label22.Text = rs.GetDirectoryEntry().Properties["sn"].Value.ToString();
        //if (rs.GetDirectoryEntry().Properties["userAccountControl"].Value != null)
        //    TextBox4.Text = "value : " + rs.GetDirectoryEntry().Properties["userAccountControl"].Value.ToString();
        if (rs.GetDirectoryEntry().Properties["userAccountControl"].Value != null)
            acc = rs.GetDirectoryEntry().Properties["userAccountControl"].Value.ToString();
        //if (String.Compare(acc, "512")==-1)
        if (acc=="512")
        {
            Label24.ForeColor = System.Drawing.Color.Green;
            Label24.Text = "Enabled Account";
        }
        if (acc == "514")
        {
            Label24.ForeColor = System.Drawing.Color.Red;
            Label24.Text = "Disabled Account";
        }
        if (acc == "544")
        {
            Label24.ForeColor = System.Drawing.Color.Gold;
            Label24.Text = "Enabled, Password Not Required";
        }
        if (acc == "546")
        {
            Label24.ForeColor = System.Drawing.Color.Red;
            Label24.Text = "Disabled, Password Not Required";
        }
        if (acc == "66050")
        {
            Label24.ForeColor = System.Drawing.Color.Red;
            Label24.Text = "Disabled, Password Doesn't Expire";
        }
        if (acc == "66048")
        {
            Label24.ForeColor = System.Drawing.Color.Gold;
            Label24.Text = "Enabled, Password Doesn't Expire";
        }
        if (acc == "66080")
        {
            Label24.ForeColor = System.Drawing.Color.Gold;
            Label24.Text = "Enabled, Password Doesn't Expire & Not Required";
        }
        if (acc == "66082")
        {
            Label24.ForeColor = System.Drawing.Color.Red;
            Label24.Text = "Disabled, Password Doesn't Expire & Not Required";
        }
        Int64 pls = 1;
        if (rs.GetDirectoryEntry().Properties["pwdLastSet"] != null && rs.GetDirectoryEntry().Properties["pwdLastSet"].Value != null)
        {
            pls = ConvertADSLargeIntegerToInt64(rs.GetDirectoryEntry().Properties["pwdLastSet"].Value);
        }
        //else
        //{
        //    throw new Exception("Nu am putut determina!");
        //}
        Label30.ForeColor = System.Drawing.Color.Green;
        Label30.Text = "NU <font color='"black'">(Nota: functie netestata.)</font>";
        if (pls == 0)
        {
            Label30.Text = "DA <font color='"black'">(Nota: functie netestata.)</font>";
        }
//

/

private static Int64 ConvertADSLargeIntegerToInt64(object adsLargeInteger)
    {
        var highPart = (Int32)adsLargeInteger.GetType().InvokeMember("HighPart", System.Reflection.BindingFlags.GetProperty, null, adsLargeInteger, null);
        var lowPart = (Int32)adsLargeInteger.GetType().InvokeMember("LowPart", System.Reflection.BindingFlags.GetProperty, null, adsLargeInteger, null);
        return highPart * ((Int64)UInt32.MaxValue + 1) + lowPart;
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        PrincipalContext insPrincipalContext = new PrincipalContext(ContextType.Domain, blabla);
        string valEx = @"'<'w'>";
        //if (!(Regex.IsMatch(this.TextBox1.Text.Trim(), valEx)))

        try
        {
            if (TextBox1.Text.Trim().Length != 0)
            {
                GetUserInformation(username, passowrd, domain);
                UserPrincipal user = UserPrincipal.FindByIdentity(insPrincipalContext, TextBox1.Text);
                //textBox1.Text = user.ToString();
                Label23.ForeColor = System.Drawing.Color.Red;

                string pla = user.LastPasswordSet.ToString();
                Label28.Text = pla + " (Format: MM/DD/YYY)";
                //DateTime expiration = user.AccountExpirationDate.Value.ToLocalTime();
                if (user.AccountExpirationDate != null)
                {
                    string expiration = user.AccountExpirationDate.ToString();
                    Label32.Text = expiration.ToString();
                }
                else
                {
                    Label32.Text = "NU";
                }
                if (user.IsAccountLockedOut())
                {
                    Label23.ForeColor = System.Drawing.Color.Red;
                    Label23.Text = "Locked";
                }
                else
                {
                    Label23.ForeColor = System.Drawing.Color.Green;
                    Label23.Text = "NOT Locked";
                }
            }
            else
            {
                Label23.Text = "Please enter all required inputs.";
            }
        }
        catch (Exception j)
        {
        }  

选中/取消选中 C# 活动目录特定单选按钮

首先,

您必须根据某些条件(例如用户名)搜索特定用户,然后检查特定属性:

 string UserName = "SomeLogin";     
 PrincipalContext domainContext = 
    new PrincipalContext(ContextType.Domain, "...", "... );            
 using ( var searcher = 
            new PrincipalSearcher( new UserPrincipal( domainContext ) 
                     { SamAccountName = UserName } ) )
 {
     var principal = UserPrincipal i in searcher.FindAll().ToList().FirstOrDefault();
     if ( principal != null )
     {
        // this is what you look for
        bool enabled = principal.Enabled; 
     }
 }
在第

一篇文章中在 LEE 中解决了。

亚历克斯