?? ??? ?? ??? ???? ???? ????? ?? ????? ???? ????
DirectoryServices??????? ?????? ?? ?? ???? ?? ??? ???? ?????????? ?? ????? ?? ??? ??? ????? ???
??????????
- Microsoft Windows XP, Windows 2000 ?? Windows NT 4.0
- ????? C#
????? ?????
- Microsoft Visual Studio .NET 2003, Microsoft Visual Studio 2005 ?? Microsoft Visual Studio 2008 ?? ??????? ????, ?? ???? ??? ????? C# ????? ????????? ??? ??? ????????? ??????
- ?????? Explorer ???, ???? ????????????? ????-????? ????, ?? ???? ????????? ??????.
- ???? ?????? ??????System.DirectoryServices.dll????????
- Class1.cs ????? ??? ??? ?? ????? ??? ?? ???????????? ?????
???:Microsoft Visual C# 2005 ?? Visual Microsoft C# 2008, ??? Class1.cs ????? Program.cs ????? ?? ???????????? ???? ???
using System;
using System.DirectoryServices;
class Class1
{
static void Main(string[] args)
{
try
{
DirectoryEntry AD = new DirectoryEntry("WinNT://" +
Environment.MachineName + ",computer");
DirectoryEntry NewUser = AD.Children.Add("TestUser1", "user");
NewUser.Invoke("SetPassword", new object[] {"#12345Abc"});
NewUser.Invoke("Put", new object[] {"Description", "Test User from .NET"});
NewUser.CommitChanges();
DirectoryEntry grp;
grp = AD.Children.Find("Guests", "group");
if (grp != null) {grp.Invoke("Add", new object[] {NewUser.Path.ToString()});}
Console.WriteLine("Account Created Successfully");
Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.ReadLine();
}
}
}
- ?????? ????, ?? ??? ????????? ?? ??????
- ???????? ???? ?? ???? ????? ??? ?? ?? ????? ???? ??? ????? ???? ?? ??? Windows 2000-?????? ???????? ?? ????? ????? ?? ???? ????:
- ????????????? ??,????????????? ????? ????,???????????? ??????? ????-????? ????, ?? ???? ??????????? ???????.
- ??????? ???? ?? ??? ????? ??????????? ?????????? ?? ??????? ??? ?? ???? ?? ??????? ????? ???? ?????Users???, ??? ?? ???? ?? ??? ??? ?? ?????????????????
???????? ???? ?? ???? ????? ??? ?? ?? ????? ???? ??? ????? ???? ?? ??? Windows XP-?????? ???????? ?? ????? ????? ?? ???? ????:- ????????????? ??,???????? ????.
- ???-????? ?????????????? ????. ??? ?????????? ???? ??? ????? ???? ??????????????? ????????? ????? ?? ??????? ?? ??? ?? ..
?????????? ???: ?? ???? ?? ?????????? ???? ?? ?????? ?? ????? ???? ?????? ???? ?? ????
??? ?? ??????????
??? ?? ?????????? ????????? ?????
?? ????? ??? ?????????? ????????? ?????, ?? ?? ?? ?????? ?? ??? ?? Microsoft Windows NT, Windows 2000 ?? Windows XP ??? assumed ??? ????? ??? ?? ???????? ?? ??? ???? ??? ??
DirectoryEntryconstructor ?? ???? ???? ?? "WinNT: / /"? ?? ???? ?????-???? ???????? ???????? ?? ?? ?????????? ???? ??? ???? ????
DirectoryEntry AD = new DirectoryEntry("WinNT://" + SystemInformation.ComputerName + ",computer");
?????????? ???? ?? ??? ?????????? ????????? ??????
????? ??? ?????? ?? ??
DirectoryEntry?? ?????? ??
????????????? ?? ???
TestUser1???? ?? ???
?????? ???????????????
DirectoryEntry NewUser = AD.Children.Add("TestUser1", "user");
??????? ?? ??? ?????????? ???? ?? ??? ????? ??? ????
????? ??? ???
??????? ??????????? ???? ?? ??? ????
SetPassword, ??
?????? ??? ???????
DirectoryEntry???????? ??? ?? ??????? ??? ???? ?? ?? ?????????? ???? ?? ??? ??? ????? ???? ??? ?? ??? ?? ???
CommitChanges?????????? ?? ?????? ?? ??? ?????? ???
NewUser.Invoke("SetPassword", new object[] {"#12345Abc"});
NewUser.Invoke("Put", new object[] {"Description", "Test User from .NET"});
NewUser.CommitChanges();
?? ???? ?? ??? ???? ??????
????? ?? ??? ???? ???? ?? ???, ????? ????? ?? ???? ????:
- ?? ?????? ?? ??? ?? ????????? ????DirectoryEntry.
- ??????????? ??? ???????????? ?????ActiveDirectory???? ?? ????????? ???? ?? ??? ???
?? ?????? ???, ????? ???? ??? ?? ?????? ??? ?? ??? tests ??? ??????????? ???? ???? ??? ?? ?? ???????? ???? ?? ??? ???? ???? ??? ??? ???? ????? ??, ?? ??? ?????????? ???? ???? ??? ????? ??? ???
DirectoryEntry grp;
grp = AD.Children.Find("Guests", "group");
if (grp != null) {grp.Invoke("Add", new object[] {NewUser.Path.ToString()});}
?????? ??????
?? ???? ??? ??? ???? ?? ???? ?? ??? ?? ???? ???? ?????????? ???? ????? ?? ??? ???????? ??????????? ??? ?? ????? ?? ??? ?????? ????? ??????????? ????? ???? ?? ??? ??? ?? ??? ??????? ??? ??? ?? ?????????? ?????? ???????????? ?? ???? ?? ????? ???? ?? ?????????? ???? ????? ?? ??? ?????????? ?? ?????? ??? ????? ????????? ????
???? ID: 306273 - ????? ???????: 04 ?????? 2010 - ??????: 2.0
???? ???? ???? ??:
- Microsoft Visual C# 2008 Express Edition
- Microsoft Visual C# 2005
- Microsoft Visual C# .NET 2002 Standard Edition
| kbhowtomaster kbmt KB306273 KbMthi |
???? ?????? ??????????????????: ?? ???? ?? ???? ??????? ?? ????? ?? Microsoft ????-?????? ?????????? ?????? ?????? ???? ??? ??. Microsoft ???? ??? ????-???????? ?? ????-???????? ????? ?????? ?? ???? ???????? ???? ?? ???? ????? ????? ??? ?? ??? ?????? ?? ???? ???? ???? ??? ????? ??. ???????, ????-???????? ???? ????? ???? ???? ???? ???. ?????, ????????, ?????-???? ?? ??????? ?? ???????? ?? ???? ???, ???? ?? ??? ?????? ???? ???? ??? ????? ??? ?? ???? ??. Microsoft ??????? ??? ???? ?? ?????? ?? ??????????, ????????? ?? ??? ?????? ?? ???? ????? ?? ???? ???????? ?? ??? ???? ????? ?? ??? ????????? ???? ??. Microsoft ????-?????? ?????????? ?? ????? ?????? ?? ?? ??? ??.
?????????? ?? ??????? ????????? ??????? ??:
306273
(http://support.microsoft.com/kb/306273/en-us/
)