惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

J
Java Code Geeks
腾讯CDC
Jina AI
Jina AI
博客园 - 司徒正美
博客园 - 三生石上(FineUI控件)
Apple Machine Learning Research
Apple Machine Learning Research
GbyAI
GbyAI
WordPress大学
WordPress大学
Hugging Face - Blog
Hugging Face - Blog
T
The Blog of Author Tim Ferriss
小众软件
小众软件
M
MIT News - Artificial intelligence
MyScale Blog
MyScale Blog
D
Docker
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Google DeepMind News
Google DeepMind News
月光博客
月光博客
L
LangChain Blog
F
Fortinet All Blogs
Microsoft Azure Blog
Microsoft Azure Blog
博客园 - Franky
C
Check Point Blog
U
Unit 42
人人都是产品经理
人人都是产品经理

博客园 - bestcomy

在OPENSUE 11.3 上安装 sysstat Upload bug in MOSS 2007 / Windows Server 2008 - bestcomy Excel列名转换 Clienside ProgressIndicator - bestcomy - 博客园 ASP.NET MVC 源代码发布! 微软项目组招聘.NET开发人员(北京) 欢迎访问我的新BLOG空间 SharePoint 胡言乱语 你觉得vs.net那些地方让你使用起来很不爽? Include javascript and css dynamically - bestcomy Two ways to get HtmlTextWriter for HTML rendering How to set value for webpart’s properties when I create a new sharepoint template Get the true value of a calculate field in SharePoint 调用自定义event时需要注意的一个问题 self==top 微软 and 香烟 Cool!!! Virtual Earth Technology Preview sth about our coding life 还没有Windows Live Messenger的朋友看过来
如何设置AD用户的"用户下次登陆时须更改密码"属性 (LDAP...
bestcomy · 2006-07-04 · via 博客园 - bestcomy

最近要给客户做培训需要配置一个测试环境,因为系统使用域用户验证,建立大量的域用户工作量比较大,而且测试环境的用户名可以根据用户单位和角色建立一个用户名模式,例如:角色.单位

于是用c#批量建立用户,发现这样两个比较棘手的问题:
1. 如何设置用户名初始密码
2. 如何设置“用户下次登陆时须更改密码”不选中(缺省选中)

最终的测试建立用户的代码如下:

 1 DirectoryEntry AD = new DirectoryEntry("LDAP://dc=cnblogs,dc=com","administrator","pa$$word",AuthenticationTypes.Secure);
 2             DirectorySearcher searcher = new DirectorySearcher(AD);
 3             searcher.Filter = String.Format("ou={0}","Blogs");
 4             SearchResult result = searcher.FindOne();
 5             if(result!=null)
 6             {
 7                 string samAccountName = "tester";
 8                 string displayName = "测试创建";
 9                 DirectoryEntry userEntry = result.GetDirectoryEntry().Children.Add(String.Format("CN={0}",samAccountName),"User");
10                 userEntry.Properties["sAMAccountName"].Add(samAccountName);
11                 userEntry.Properties["displayName"].Add(displayName);
12                 userEntry.Properties["UserPassword"].Add("pa$$word");
13                 userEntry.Properties["userAccountControl"].Value = 544;
14                 userEntry.Properties["pwdLastSet"].Value = -1;
15                 userEntry.CommitChanges();
16                 userEntry.Invoke("SetPassword",new object[] {"pa$$word"});
17             }

顺便做一个小小的招聘广告,哈哈,大家见谅。
朋友最近要我推荐几个程序员,北京地区的.net程序员均可将简历通过以下地址给我
bestcomy at hotmail.com   ( at 替换为@)
请在简历上写好联系方式,如果合适会主动有人联系你。