IADObject
1// CreateBy : xuzhong
2// CreateTime : 2003-08-08
3// Version : 1.0
4using System;
5
6namespace XZSoftware.ActiveDirectoryLib {
7 /**//// <summary>
8 /// IADObject活动目录基本接口
9 /// </summary>
10 public interface IADObject {
11 /**//// <summary>
12 /// 获得显示名
13 /// </summary>
14 string Name {
15 get;
16 }
17
18 /**//// <summary>
19 /// 获得adsPath路径
20 /// </summary>
21 string AdsPath {
22 get;
23 }
24
25 /**//// <summary>
26 /// 获取 DirectoryEntry 的全局唯一标识符 (GUID)。
27 /// </summary>
28 Guid Guid {
29 get;
30 }
31 }
32}
33
1// CreateBy : xuzhong
2// CreateTime : 2003-08-08
3// Version : 1.0
4using System;
5
6namespace XZSoftware.ActiveDirectoryLib {
7 /**//// <summary>
8 /// IADObject活动目录基本接口
9 /// </summary>
10 public interface IADObject {
11 /**//// <summary>
12 /// 获得显示名
13 /// </summary>
14 string Name {
15 get;
16 }
17
18 /**//// <summary>
19 /// 获得adsPath路径
20 /// </summary>
21 string AdsPath {
22 get;
23 }
24
25 /**//// <summary>
26 /// 获取 DirectoryEntry 的全局唯一标识符 (GUID)。
27 /// </summary>
28 Guid Guid {
29 get;
30 }
31 }
32}
33
ADObject
1/**//*
2 * CreateBy : xuzhong
3 * CreateTime : 2003-08-08
4 * Version : 0.1
5 *
6 */
7
8using System;
9using System.DirectoryServices ;
10
11namespace XZSoftware.ActiveDirectoryLib {
12 /**//// <summary>
13 /// ADObject 的摘要说明。
14 /// </summary>
15 public class ADObject:IADObject {
16
17 /**//// <summary>
18 /// 对AD进行处理所要用的工具
19 /// </summary>
20 public static IADUtility Utility;
21
22 /**//// <summary>
23 /// 当前DirectoryEntry实例对象
24 /// </summary>
25 private DirectoryEntry m_directoryEntry;
26
27 public ADObject() {
28 }
29 /**//// <summary>
30 /// 通过DirectoryEntry对象实例化该类
31 /// </summary>
32 /// <param name="directoryEntry">directoryEntry对象</param>
33 public ADObject(DirectoryEntry directoryEntry){
34 this.m_directoryEntry = directoryEntry ;
35 }
36
37 IADObject 成员#region IADObject 成员
38 public string AdsPath {
39 get {
40 return this.m_directoryEntry.Path;
41 }
42 }
43
44 /**//// <summary>
45 /// 返回Name
46 /// </summary>
47 public string Name {
48 get {
49 return this.m_directoryEntry.Name;
50 }
51 }
52
53 /**//// <summary>
54 /// 返回唯一Guid
55 /// </summary>
56 public Guid Guid {
57 get {
58 return this.m_directoryEntry.Guid;
59 }
60 }
61
62 #endregion
63
64
65 /**//// <summary>
66 /// 设置指定属性的值
67 /// </summary>
68 /// <param name="property">属性名</param>
69 /// <param name="value">更新数据</param>
70 public void SetProperty(string property, object value) {
71 int propertyCount ;
72 try{
73 propertyCount = this.m_directoryEntry.Properties[property].Count ;
74 }catch{
75 throw( new ADPropertyException("当前对象没有'"
76 + property + "'属性,操作不被允许。"));
77 }
78 if (propertyCount !=0){
79 this.m_directoryEntry.Properties[property][0] = value ;
80 } else{
81 this.m_directoryEntry.Properties[property].Add(value) ;
82 }
83 try{
84 this.m_directoryEntry.CommitChanges() ;
85 }catch{
86 throw( new ADPropertyException("更新属性'"
87 +property+"'失败,操作不被允许,"
88 + "可能是当前用户没有权限。"));
89 }
90 }
91
92 /**//// <summary>
93 /// 获取指定属性名的第一个值
94 /// </summary>
95 /// <param name="property"></param>
96 /// <returns></returns>
97 public object GetProperty(string property){
98 int propertyCount ;
99 try{
100 propertyCount = this.m_directoryEntry.Properties[property].Count ;
101 }catch{
102 throw( new ADPropertyException("当前对象没有'"
103 + property + "'属性,无法取得该值。"));
104 }
105 if(propertyCount != 0){
106 try
1/**//*
2 * CreateBy : xuzhong
3 * CreateTime : 2003-08-08
4 * Version : 0.1
5 *
6 */
7
8using System;
9using System.DirectoryServices ;
10
11namespace XZSoftware.ActiveDirectoryLib {
12 /**//// <summary>
13 /// ADObject 的摘要说明。
14 /// </summary>
15 public class ADObject:IADObject {
16
17 /**//// <summary>
18 /// 对AD进行处理所要用的工具
19 /// </summary>
20 public static IADUtility Utility;
21
22 /**//// <summary>
23 /// 当前DirectoryEntry实例对象
24 /// </summary>
25 private DirectoryEntry m_directoryEntry;
26
27 public ADObject() {
28 }
29 /**//// <summary>
30 /// 通过DirectoryEntry对象实例化该类
31 /// </summary>
32 /// <param name="directoryEntry">directoryEntry对象</param>
33 public ADObject(DirectoryEntry directoryEntry){
34 this.m_directoryEntry = directoryEntry ;
35 }
36
37 IADObject 成员#region IADObject 成员
38 public string AdsPath {
39 get {
40 return this.m_directoryEntry.Path;
41 }
42 }
43
44 /**//// <summary>
45 /// 返回Name
46 /// </summary>
47 public string Name {
48 get {
49 return this.m_directoryEntry.Name;
50 }
51 }
52
53 /**//// <summary>
54 /// 返回唯一Guid
55 /// </summary>
56 public Guid Guid {
57 get {
58 return this.m_directoryEntry.Guid;
59 }
60 }
61
62 #endregion
63
64
65 /**//// <summary>
66 /// 设置指定属性的值
67 /// </summary>
68 /// <param name="property">属性名</param>
69 /// <param name="value">更新数据</param>
70 public void SetProperty(string property, object value) {
71 int propertyCount ;
72 try{
73 propertyCount = this.m_directoryEntry.Properties[property].Count ;
74 }catch{
75 throw( new ADPropertyException("当前对象没有'"
76 + property + "'属性,操作不被允许。"));
77 }
78 if (propertyCount !=0){
79 this.m_directoryEntry.Properties[property][0] = value ;
80 } else{
81 this.m_directoryEntry.Properties[property].Add(value) ;
82 }
83 try{
84 this.m_directoryEntry.CommitChanges() ;
85 }catch{
86 throw( new ADPropertyException("更新属性'"
87 +property+"'失败,操作不被允许,"
88 + "可能是当前用户没有权限。"));
89 }
90 }
91
92 /**//// <summary>
93 /// 获取指定属性名的第一个值
94 /// </summary>
95 /// <param name="property"></param>
96 /// <returns></returns>
97 public object GetProperty(string property){
98 int propertyCount ;
99 try{
100 propertyCount = this.m_directoryEntry.Properties[property].Count ;
101 }catch{
102 throw( new ADPropertyException("当前对象没有'"
103 + property + "'属性,无法取得该值。"));
104 }
105 if(propertyCount != 0){
106 try