【发布时间】:2014-12-20 18:45:40
【问题描述】:
我有一个名为用户提取的应用程序,顾名思义,该应用程序的目标是通过从列表框中选择用户来提取有关用户的所有可能信息,选择 samsaccount 名称并作为值到 txtusersearcher.text 文本框中,我正在做一个SearchUserName.PerformClick(); 我为每个属性创建了一个文本框,并且属性的值设置为等于文本框。
我尝试过的事情
1)
private void GetUserInformation(string username, string passowrd, string domain)
{
Cursor.Current = Cursors.WaitCursor;
SearchResult rs = null;
if (txtSearchUser.Text.Trim().IndexOf("@") > 0)
rs = SearchUserByEmail(GetDirectorySearcher(username, passowrd, domain), txtSearchUser.Text.Trim());
else
rs = SearchUserByUserName(GetDirectorySearcher(username, passowrd, domain), txtSearchUser.Text.Trim());
if (rs != null)
{
showuserinfo();
ShowUserInformation(rs);
}
else
{
MessageBox.Show("User not found!!!", "Search Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
private void ShowUserInformation(SearchResult rs)
{if (rs.GetDirectoryEntry().Properties["lastLogon"].Value != null)
lastlog.Text = rs.GetDirectoryEntry().Properties["lastLogon"].Value.ToString();
2)
if (rs.GetDirectoryEntry().Properties["lastLogon"].Value != null)
lastlog.Text = (rs.GetDirectoryEntry().Properties["lastLogon"].Value.ToString());
int x;
x = Int32.Parse(lastlog.Text);
lastlog.Text = x.ToString();
3) 我在网上看到使用主体上下文、用户主体和主体搜索器可以解决问题并尝试了这个
PrincipalContext ctx = new PrincipalContext(ContextType.Domain);
UserPrincipal qbeuser = new UserPrincipal(ctx);
PrincipalSearcher srch = new PrincipalSearcher(qbeuser);
foreach (var found in srch.FindAll())
{
UserPrincipal founduser = found as UserPrincipal;
{
if (founduser.LastLogon != null)
lastlog.Text = founduser.LastLogon.ToString();
}
}
这可行,但这会在列表框中引入第一个用户的 lastlogon,我希望在单击每个用户时更改此值。我知道主要原因是 lastlogon 值存储为 integer8 ,而其他值是字符串。当你使用 value.tostring();它不起作用,我收到System.__ComObject 错误。人们建议使用演员,但我是这项技术的新手,非常感谢示例转换代码,非常感谢这个问题的解决方法谢谢你们!!!!!!!!!!!!
【问题讨论】:
-
@DJKRAZE 如果您想知道这个问题实际上与我之前提出的问题相同,我认为问题已得到解决,我几乎不知道如果只是返回第一个用户的 lastLogon 时间列表框,对于被选中的任何用户,文本框具有相同的值,因此任何关于如何使 lastlog 文本框中的文本为每个用户更改的建议。
标签: c# winforms active-directory ldap directoryservices