+++++++++++高手入+++++++++++++++

einsteincao 2005-10-17 11:31:27
想建立一个webservice
其中有2个方法
是关于系统的security的
AddGroup() 添加系统中的组

AddUser() 添加系统中的用户
...全文
180 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
sxlfybb 2005-10-17
  • 打赏
  • 举报
回复
System.DirectoryServices这个引用
点击菜单项目>点击添加引用>然后在.net里面选择就可以了.

using System.Net;这个就不用说了吧?

DirectoryEntry AD = new DirectoryEntry("WinNT://" + Dns.GetHostByAddress(IPAddress.Parse(textBox1.Text)).HostName + ",computer");

Dns.GetHostByAddress(IPAddress.Parse(textBox1.Text)).HostName 这个是我通过输入IP地址来获取计算机名称的,你在实际使用过程中,可以直接写入计算机名称,比如:

DirectoryEntry AD = new DirectoryEntry("WinNT://TempHost,computer");

关于DirectoryEntry 的使用方法,你可以参考一下MSDN.

如果你的测试不能通过.再留言吧.
desailly 2005-10-17
  • 打赏
  • 举报
回复

jetxia 2005-10-17
  • 打赏
  • 举报
回复
首先你要知道自己用户的AD Path,例如LDAP://Domain.com/CN=user1,CN=Users,DC=domain,DC=com
然后使用System.DirectoryServices.DirectoryEntry就可以取得对应的AD对象了,其中的"memberof"属性就是用户所在的group的列表。

You can have a look with the sample in MSDN with following URL too:
ms-help://MS.VSCC/MS.MSDNVS/cpref/html/frlrfsystemdirectoryservicessearchresultclasstopic.htm

Something like this:

using System.DirectoryServices;
...

string adPath = @"LDAP://Domain.com/CN=user1,CN=Users,DC=domain,DC=com";
DirectoryEntry user = new DirectoryEntry (adPath);

foreach(object group in user.Properties["memberof"])
{
Console.WriteLine(group.ToString());
}
jetxia 2005-10-17
  • 打赏
  • 举报
回复
先在项目中引用System.DirectoryServices.dll
然后using System.DirectoryServices;
einsteincao 2005-10-17
  • 打赏
  • 举报
回复
DirectoryEntry AD = new DirectoryEntry("WinNT://" + Dns.GetHostByAddress(IPAddress.Parse(textBox1.Text)).HostName + ",computer");


有没有标准写法?
dragonfly001 2005-10-17
  • 打赏
  • 举报
回复
點擊你的專案,然後右鍵,加入參考 ,選擇System.DirectoryServices.dll
然後在源代碼中加入using System.DirectoryServices
就可以應用了
einsteincao 2005-10-17
  • 打赏
  • 举报
回复
using System.DirectoryServices
怎样获得呢?
jetxia 2005-10-17
  • 打赏
  • 举报
回复
首先你的webservice(asp.net用户)得有这样的权限
然后通过楼上的方法
自由程序员 2005-10-17
  • 打赏
  • 举报
回复
高手,还不是得搜资料来看
sxlfybb 2005-10-17
  • 打赏
  • 举报
回复
需要额外using的命名空间:

using System.DirectoryServices;
using System.Net;
sxlfybb 2005-10-17
  • 打赏
  • 举报
回复
手边正好有一个WinForm的,仅供参考.

try
{
DirectoryEntry AD = new DirectoryEntry("WinNT://" + Dns.GetHostByAddress(IPAddress.Parse(textBox1.Text)).HostName + ",computer");
DirectoryEntry xUser = AD.Children.Add ("GZB","user");
xUser.Invoke("SetPassword",new object[]{"gzb"});
xUser.Invoke("Put",new object[]{"description","test"});
xUser.CommitChanges();

DirectoryEntry GP = AD.Children.Find("Administrators","Group");
if ( GP!=null)
{
GP.Invoke( "ADD", new object[]{xUser.Path.ToString()} );
}

MessageBox.Show("成功!");
}
catch( Exception ex )
{
MessageBox.Show ( ex.Message );
}
sxlfybb 2005-10-17
  • 打赏
  • 举报
回复
活动目录 (AD) 的问题.
yegucheng 2005-10-17
  • 打赏
  • 举报
回复
可以实现,查看关于域方面的类库,应该有这个方法的
einsteincao 2005-10-17
  • 打赏
  • 举报
回复
我的问题是:
想建立一个WebService
这个WebService需要实现2个功能(也就是说,添加2个方法)
1. AddGroup 添加Windows中的组(group)
2. AddUser 添加Windows中得用户(user)

例如: 向Guest 组中加入一个用户 MyGuest1
mathsword 2005-10-17
  • 打赏
  • 举报
回复
你的问题是什么?

110,526

社区成员

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

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

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