任何人都可以幫我解決下面的問題嗎?C#Active Directory特定的單選按鈕已選中/未選中
我想查看是否選中或取消選中活動目錄中的特定單選按鈕。 婁你有一個鏈接單選按鈕的PRINTSCREEN(用紅色標出)
http://media.ipsosinteractive.com/projects/S1027838/img/pic.jpg
謝謝!
LE:
我用的System.DirectoryServices;
如果我可以通過System.DirectoryServices.AccountManagement建立與AD的連接,那將非常容易。
我不知道如何連接?
比方說,我有域:office.company.intra
PrincipalContext domainContext =新PrincipalContext(ContextType.Domain, 「...」 「DC = ..,DC = ..,DC = ..」,systemAccount,systemAccountPassword);
LEE - 以備將來參考AD exemples:
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)
{
}