AD用户属性&C#操作实例
2009-04-05 15:44
579 查看
AD用户属性&C#操作实例
属性
帐号属性:
地址属性
成员属性
组织属性
外型属性
电话相关属性
C#操作AD例子:
GetUserEntry
public static DirectoryEntry GetUserEntryByAccount(DirectoryEntry entry, string account)
{
DirectorySearcher searcher = new DirectorySearcher(entry);
searcher.Filter = "(&(objectClass=user)(SAMAccountName=" + account + "))";
SearchResult result = searcher.FindOne();
entry.Close();
if (result != null)
{
return result.GetDirectoryEntry();
}
return null;
}
Set Property
public static void SetProperty(DirectoryEntry entry, string propertyName, string propertyValue)
{
if (entry.Properties.Contains(propertyName))
{
if (string.IsNullOrEmpty(propertyValue))
{
object o = entry.Properties[propertyName].Value;
entry.Properties[propertyName].Remove(o);
}
else
{
entry.Properties[propertyName][0] = propertyValue;
}
}
else
{
if (string.IsNullOrEmpty(propertyValue))
{
return;
}
entry.Properties[propertyName].Add(propertyValue);
}
}
Get Property
public static string GetProperty(DirectoryEntry entry, string propertyName)
{
if (entry.Properties.Contains(propertyName))
{
return entry.Properties[propertyName].Value.ToString();
}
else
{
return string.Empty;
}
}
属性
显示名称 | 属性名称 |
First Name | givenName |
Last Name | sn |
Initials | initials |
Description | description |
Office | physicalDeliveryOfficeName |
Telephone Number | telephoneNumber |
Telephone: Other | otherTelephone |
E-Mail | mail |
Web Page | wwwHomePage |
Web Page: Other | url |
显示名称 | 属性名称 |
UserLogon Name | userPrincipalName |
User logon name (pre-Windows 2000) | sAMAccountname |
Logon Hours | logonHours |
Log On To | logonWorkstation |
Account is locked out | userAccountControl |
User must change password at next logon | pwdLastSet |
User cannot change password | N/A |
Other Account Options | userAccountControl |
Account Expires | accountExpires |
显示名称 | 属性名称 |
Street | streetAddress |
P.O.Box | postOfficeBox |
City | l |
State/Province | st |
Zip/Postal Code | postalCode |
Country/Region | c, co, and countryCode |
显示名称 | 属性名称 |
Member of | memberOf< 11586 /span> |
Set Primary Group | primaryGroupID |
显示名称 | 属性名称 |
Title | title |
Department | department |
Company | company |
Manager:Name | manager |
Direct Reports | directReports |
显示名称 | 属性名称 |
Profile Path | profilePath |
Logon Script | scriptPath |
Home Folder: Local Path | homeDirectory |
Home Folder: Connect | homeDrive |
Home Folder: To | homeDirectory |
显示名称 | 属性名称 |
Home | telephoneNumber |
Home: Other | otherTelephone |
Pager | pager |
Pager: Other | pagerOther |
Mobile | mobile |
Mobile: Other | otherMobile |
Fax | facsimileTelephoneNumber |
Fax: Other | otherFacsimileTelephoneNumber |
IP phone | ipPhone |
IP phone: Other | otherIpPhone |
Notes | info |
GetUserEntry
public static DirectoryEntry GetUserEntryByAccount(DirectoryEntry entry, string account)
{
DirectorySearcher searcher = new DirectorySearcher(entry);
searcher.Filter = "(&(objectClass=user)(SAMAccountName=" + account + "))";
SearchResult result = searcher.FindOne();
entry.Close();
if (result != null)
{
return result.GetDirectoryEntry();
}
return null;
}
Set Property
public static void SetProperty(DirectoryEntry entry, string propertyName, string propertyValue)
{
if (entry.Properties.Contains(propertyName))
{
if (string.IsNullOrEmpty(propertyValue))
{
object o = entry.Properties[propertyName].Value;
entry.Properties[propertyName].Remove(o);
}
else
{
entry.Properties[propertyName][0] = propertyValue;
}
}
else
{
if (string.IsNullOrEmpty(propertyValue))
{
return;
}
entry.Properties[propertyName].Add(propertyValue);
}
}
Get Property
public static string GetProperty(DirectoryEntry entry, string propertyName)
{
if (entry.Properties.Contains(propertyName))
{
return entry.Properties[propertyName].Value.ToString();
}
else
{
return string.Empty;
}
}
相关文章推荐
- AD用户属性&C#操作实例
- Oracle 远程访问配置 在 Windows Forms 和 WPF 应用中使用 FontAwesome 图标 C#反序列化XML异常:在 XML文档(0, 0)中有一个错误“缺少根元素” C#[Win32&WinCE&WM]应用程序只能运行一个实例:MutexHelper Decimal类型截取保留N位小数向上取, Decimal类型截取保留N位小数并且不进行四舍五入操作
- C# 访问AD中用户信息的几个操作
- AD帐户操作C#示例代码(二)——检查密码将过期的用户
- 在C#中访问AD用户信息的示例操作
- C#通过XML节点属性/属性值读取写入XML操作代码实例
- AD帐户操作C#示例代码(一)——导入用户信息
- c# 域操作实例 AD身份验证
- C#使用XmlDocument操作XML进行查询、增加、修改、删除、保存应用的实例(转载)
- 域用户自助修改AD属性Web应用 - ADCustomWeb
- [转]C#连接操作mysql实例
- 在C#中操作XML 经典实例
- C#操作MongoDB的简单实例
- js里设置<a>标签的data-rel属性实例
- 用户管理模式下的备份操作【实例】
- HTTP协议及其POST与GET操作差异 & C#中如何使用POST、GET等
- C#文件读写IO操作 实例
- oracle进阶【一】之初出茅庐—>oracle用户及权限管理实例操作
- 为AD中的用户设置send as安全属性