用DirectoryEntry新建AD用户,怎样可以让“密码永不过期”?

Ki1381 2007-12-11 06:17:17
不知道对应的是哪个属性,谢谢!
...全文
761 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
zxkid 2007-12-12
  • 打赏
  • 举报
回复
user.Properties["userAccountControl"].Value = 0x00010000 | ...; //0x00010000 = ADS_UF_DONT_EXPIRE_PASSWD
user.CommitChanges();

参照ms-help://MS.VSCC.v80/MS.MSDN.v80/MS.WIN32COM.v10.en/adschema/adschema/a_useraccountcontrol.htm
spgoal 2007-12-12
  • 打赏
  • 举报
回复
using System;
using System.DirectoryServices;

namespace DChelper
{
/// <summary>
/// DCHelper 的摘要说明。
/// </summary>
public class DCHelper
{
public DCHelper()
{
//
// TODO: 在此处添加构造函数逻辑
//
}

public void CreateOu(string ouname,string parent,string oucode)
{
String RootDSE;
DirectoryEntry myDE=null;
System.DirectoryServices.DirectorySearcher DSESearcher
= new System.DirectoryServices.DirectorySearcher();
RootDSE=DSESearcher.SearchRoot.Path;
if (parent==null)
{

myDE = new DirectoryEntry(RootDSE);
}
else
{
DSESearcher=new DirectorySearcher(RootDSE);
DSESearcher.Filter="(&(objectClass=organizationalUnit)(ou=" + parent + "))";
SearchResult mySearchResult = DSESearcher.FindOne();
myDE = mySearchResult.GetDirectoryEntry();
}

DirectoryEntries myEntries = myDE.Children;

DirectoryEntry myDirectoryEntry =
myEntries.Add("OU=" + ouname,"organizationalUnit");

myDirectoryEntry.Properties["name"].Value=ouname;
myDirectoryEntry.Properties["ou"].Value=ouname;
myDirectoryEntry.Properties["postalCode"].Value=oucode;

myDirectoryEntry.CommitChanges();
}

public void CreateUser(string account,string strPwd,string ouname,string displayname)
{
DirectoryEntry obDirEntry = null;
try
{
String RootDSE;
System.DirectoryServices.DirectorySearcher DSESearcher
= new System.DirectoryServices.DirectorySearcher();
RootDSE=DSESearcher.SearchRoot.Path;
if(ouname==null)
{
obDirEntry = new DirectoryEntry(RootDSE);
DirectoryEntries entries = obDirEntry.Children;
DirectoryEntry obUser = entries.Add("CN=" + account, "user");
obUser.Properties["company"].Value="暨南大学附属第一医院";
obUser.Properties["department"].Value=ouname;
obUser.Properties["mail"].Value=account+"@jd120.com";
//obUser.Properties["title"].Value=zhicheng;
obUser.Properties["displayname"].Value=displayname;
obUser.Properties["samAccountName"].Value=account;
obUser.Properties["userAccountControl"][0] = 0X10000 | 0X0200;//启用用户

//object obRet = obUser.Invoke("SetPassword", strPwd);
obUser.CommitChanges();
}
else
{
DSESearcher=new DirectorySearcher(RootDSE);
DSESearcher.Filter="(&(objectClass=organizationalUnit)(ou=" + ouname + "))";
SearchResult mySearchResult = DSESearcher.FindOne();
if(mySearchResult.GetDirectoryEntry()!=null)
{
obDirEntry = mySearchResult.GetDirectoryEntry();
DirectoryEntries entries = obDirEntry.Children;
DirectoryEntry obUser = entries.Add("CN=" + account, "user");
obUser.Properties["company"].Value="暨南大学附属第一医院";
obUser.Properties["department"].Value=ouname;
obUser.Properties["mail"].Value=account+"@jd120.com";
//obUser.Properties["title"].Value=zhicheng;
obUser.Properties["displayname"].Value=displayname;
obUser.Properties["samAccountName"].Value=account;
obUser.Properties["userAccountControl"].Value = 0X10000 | 0X0200;//启用用户
//object obRet = obUser.Invoke("SetPassword", strPwd);
obUser.CommitChanges();
}

}

}
catch (Exception ex)
{
throw ex;

}

}
}
}
  • 打赏
  • 举报
回复
up

110,561

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧