怎么样才能在.net下对Windows用户进行操作?

colin666 2003-01-14 05:15:05
怎么样可以在.net下对Windows用户进行操作?例如添加或删除一个WINDOWS2000用户并设置其用户属性?
...全文
74 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
colin666 2003-01-17
  • 打赏
  • 举报
回复
up
colin666 2003-01-15
  • 打赏
  • 举报
回复
现在我能够添加一个用户或者添加一个GROUP了,
DirectoryEntry newde;
newde = directoryEntry1.Parent.Children.Add("testertext",directoryEntry1.SchemaClassName);
newde.CommitChanges();
请问我怎么能设置用户的属性,例如用户密码,所属的组等等?
chinchy 2003-01-15
  • 打赏
  • 举报
回复
public void AddUser()
{
string strDomain="";
String RootDSE;
System.DirectoryServices.DirectorySearcher DSESearcher
= new System.DirectoryServices.DirectorySearcher();
RootDSE=DSESearcher.SearchRoot.Path;
MessageBox.Show(RootDSE);
RootDSE=RootDSE.Insert(7,"CN=Users,");
MessageBox.Show(RootDSE);
MessageBox.Show(strDomain);
DirectoryEntry myDE = new DirectoryEntry(RootDSE);
DirectoryEntries myEntries = myDE.Children;
// Create a new entry 'Sample' in the container.
DirectoryEntry myDirectoryEntry =
myEntries.Add("CN="+txtUserName.Text, "user");
MessageBox.Show(myDirectoryEntry.SchemaClassName.ToString());
myDirectoryEntry.Properties["userPrincipalName"].Value=txtPrincipal.Text;
myDirectoryEntry.Properties["name"].Value=txtUserName.Text;
myDirectoryEntry.Properties["samAccountName"].Value=txtUserName.Text;
myDirectoryEntry.CommitChanges();
}
private void button2_Click(object sender, System.EventArgs e)
{
String RootDSE;
System.DirectoryServices.DirectorySearcher DSESearcher =
new System.DirectoryServices.DirectorySearcher();
RootDSE=DSESearcher.SearchRoot.Path;
MessageBox.Show("Searching for user Class in "+RootDSE);
DirectoryEntry entry = new DirectoryEntry(RootDSE);
System.DirectoryServices.DirectorySearcher mySearcher = new
System.DirectoryServices.DirectorySearcher(entry);
mySearcher.Filter = ("(ObjectClass=user)");
System.DirectoryServices.SearchResult resEnt=mySearcher.FindOne();
entry=resEnt.GetDirectoryEntry();
MessageBox.Show("Entry Of attribute found = "
+ entry.Properties.Contains(txtAtt.Text).ToString());
}
private void button3_Click(object sender, System.EventArgs e)
{
String RootDSE;
System.DirectoryServices.DirectorySearcher DSESearcher
= new System.DirectoryServices.DirectorySearcher();
RootDSE=DSESearcher.SearchRoot.Path;
MessageBox.Show("Searching for user Class in "+RootDSE);
DirectoryEntry entry = new DirectoryEntry(RootDSE);
System.DirectoryServices.DirectorySearcher mySearcher = new
System.DirectoryServices.DirectorySearcher(entry);
mySearcher.Filter = ("(ObjectClass=user)");
System.DirectoryServices.SearchResult resEnt=mySearcher.FindOne();
entry=resEnt.GetDirectoryEntry();
System.Collections.IEnumerator en
= entry.Properties.PropertyNames.GetEnumerator();
while(en.MoveNext())
{
listBox1.Items.Add(en.Current.ToString());
}
}
public void AddUser1()
{
string strDomain="";
String RootDSE;
System.DirectoryServices.DirectorySearcher DSESearcher
= new System.DirectoryServices.DirectorySearcher();
RootDSE=DSESearcher.SearchRoot.Path;
MessageBox.Show(RootDSE);
MessageBox.Show(RootDSE);
MessageBox.Show(strDomain);
DirectoryEntry myDE = new DirectoryEntry(RootDSE);
DirectoryEntries myEntries = myDE.Children;
// Create a new entry 'Sample' in the container.
DirectoryEntry myDirectoryEntry =
myEntries.Add("CN="+txtUserName.Text, "CB");
MessageBox.Show(myDirectoryEntry.SchemaClassName.ToString());
MessageBox.Show(myDirectoryEntry.Path.ToString());
System.Collections.IEnumerator en =
myDirectoryEntry.Properties.PropertyNames.GetEnumerator();
while(en.MoveNext())
{
MessageBox.Show(en.Current.ToString());
}
myDirectoryEntry.CommitChanges();
}
colin666 2003-01-15
  • 打赏
  • 举报
回复
up
colin666 2003-01-15
  • 打赏
  • 举报
回复
这个好象不行吧?
hhzh426 2003-01-14
  • 打赏
  • 举报
回复
WinNT: Bind to the root of the namespace.
WinNT://MyDomain Bind to the root of the MyDomain domain
WinNT://MyDomain/bob,user Bind to user MyDomain\bob
WinNT://MyDomain/dc01/MyGroup, group Bind to a group on the dc01 domain controller
WinNT://Server01,computer Bind to the Server01 computer.

------------------
LDAP://dc01 Bind to the dc01 domain controller
LDAP://exch01.arcadiabay.com Bind to an Exchange Server
LDAP://exch01:390 Bind to an Exchange Server and specify the port number

建议你看看adsi sdk帮助文件
colin666 2003-01-14
  • 打赏
  • 举报
回复
PATH怎么设啊?
colin666 2003-01-14
  • 打赏
  • 举报
回复
能不能具体一点啊
System.DirectoryServices.DirectoryEntry a=new System.DirectoryServices.DirectoryEntry(???);
hhzh426 2003-01-14
  • 打赏
  • 举报
回复
DirectoryEntry 类
colin666 2003-01-14
  • 打赏
  • 举报
回复
是不是一定要用到ADSI?有没有什么类可以做这个的?
colin666 2003-01-14
  • 打赏
  • 举报
回复
楼上能不能给一段代码?
colin666 2003-01-14
  • 打赏
  • 举报
回复
具体怎么做呢?
chinchy 2003-01-14
  • 打赏
  • 举报
回复

Active Directory

ms-help://MS.VSCC/MS.MSDNVS.2052/cpref/html/frlrfSystemDirectoryServices.htm

http://www.15seconds.com/focus/ADSI.htm

110,538

社区成员

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

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

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