C# Directory Services 連接問題

Blackson 2008-07-08 02:16:00
DC裏包含兩個NETBIOS名, 分別是PROD和TEST. 假設DC名是XXX.ORG.
程序要求: 把所有與Account Name = xxxxx同一層級的員工的Account Unlock

程序如下:

string DomainName = "TEST.XXX.ORG";
string FilterStr = "(sAMAccountname=xxxxx)";
DirectorySearcher Searcher = new DirectorySearcher(DomainName);
Searcher.Filter = FilterStr;
SearchResult SearchRes = Searcher.FindOne();
DirectoryEntry Me = SearchRes.GetDirectoryEntry();
string OUPath = Me.Parent.Path;

string Username = "MyUserName";
string Password = "MyPassword";
DirectoryEntry AdminEntry = new DirectoryEntry(OUPath, Username, Password);
foreach (DirectoryEntry TempEntry in AdminEntry.Children)
{
if (TempEntry.SchemaClassName.ToString() == "user")
{
try
{
TempEntry.Properties["LockOutTime"].Value = 0;
//Unlock Account
TempEntry.CommitChanges();
TempEntry.Close();
}
catch (System.DirectoryServices.DirectoryServicesCOMException E)
{
Console.WriteLine(E.Message);
}
}
}

當程序運行到紅色那一行代碼的時候, 便出現Unknown Username Or Bad Passowrd. 但我的帳戶跟密碼是肯定沒錯的. 這是甚麼問題呢? 跟我在本機Login with Domain PROD有關嗎? 求高手回覆 m(_ _)m
...全文
62 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
zzyhuian06142 2008-07-08
  • 打赏
  • 举报
回复
加上这个看看
把string DomainName = "TEST.XXX.ORG"; 改成
string DomainName = "LADP://TEST.XXX.ORG"; 试一下
Addison.Wesley.The.dot.NET.Developers.Guide.to.Directory.Services.Programming 英文版 "If you have any interest in writing .NET programs using Active Directory or ADAM, this is the book you want to read." Joe Richards, Microsoft MVP, directory services Identity and Access Management are rapidly gaining importance as key areas of practice in the IT industry, and directory services provide the fundamental building blocks that enable them. For enterprise developers struggling to build directory-enabled .NET applications, The .NET Developer's Guide to Directory Services Programming will come as a welcome aid. Microsoft MVPs Joe Kaplan and Ryan Dunn have written a practical introduction to programming directory services, using both versions 1.1 and 2.0 of the .NET Framework. The extensive examples in the book are in C#; a companion Web site includes both C# and Visual Basic source code and examples. Readers will Learn to create, rename, update, and delete objects in Active Directory and ADAM Learn to bind to and search directories effectively and efficiently Learn to read and write attributes of all types in the directory Learn to use directory services within ASP.NET applications Get concrete examples of common programming tasks such as managing Active Directory and ADAM users and groups, and performing authentication Experienced .NET developersthose building enterprise applications or simply interested in learning about directory serviceswill find that The .NET Developer's Guide to Directory Services Programming unravels the complexities and helps them to avoid the common pitfalls that developers face.
"If you have any interest in writing .NET programs using Active Directory or ADAM, this is the book you want to read." Joe Richards, Microsoft MVP, directory services Identity and Access Management are rapidly gaining importance as key areas of practice in the IT industry, and directory services provide the fundamental building blocks that enable them. For enterprise developers struggling to build directory-enabled .NET applications, The .NET Developer's Guide to Directory Services Programming will come as a welcome aid. Microsoft MVPs Joe Kaplan and Ryan Dunn have written a practical introduction to programming directory services, using both versions 1.1 and 2.0 of the .NET Framework. The extensive examples in the book are in C#; a companion Web site includes both C# and Visual Basic source code and examples. Readers will Learn to create, rename, update, and delete objects in Active Directory and ADAM Learn to bind to and search directories effectively and efficiently Learn to read and write attributes of all types in the directory Learn to use directory services within ASP.NET applications Get concrete examples of common programming tasks such as managing Active Directory and ADAM users and groups, and performing authentication Experienced .NET developersthose building enterprise applications or simply interested in learning about directory serviceswill find that The .NET Developer's Guide to Directory Services Programming unravels the complexities and helps them to avoid the common pitfalls that developers face.

110,603

社区成员

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

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

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