2013-08-05 47 views
1

我需要使用System.DirectoryServices在Active Directory中創建用戶,並且我無法計算如何設置gecos屬性。如何使用目錄服務(C#)在Active Directory中設置gecos屬性

嘗試這一行根本行不通:

DEUtilisateur.Properties["gecos"].Value = gecosValue 

我得到的錯誤:

指定的目錄服務屬性或值不上不存在

任何提示如何實現這一目標? 謝謝

+0

什麼版本是運行其數據庫的Active Directory服務器,未添加'gecos' [直到2003 R2](http://msdn.microsoft.com/zh-cn/library/windows/des ktop/ms675715%28V = vs.85%29.aspx)。 (請記住,您可以在較新的版本上運行較舊的模式,所以僅僅因爲您使用2008並不意味着您正在運行2008模式。) –

+0

我們正在使用窗口服務器2008,並且我100%確定模式具有gecos,因爲此屬性已經用過的。 –

回答

0

我終於找到了訪問該屬性的方式。

而不是使用直接的DirectoryEntry的連接到LDAP,如:

DirectoryEntry DEBase = new DirectoryEntry("LDAP://" + DomaineName);

我用

DirectoryContext context = new DirectoryContext(DirectoryContextType.Domain, 
        domaineName)); 

DirectoryEntry dERoot = System.DirectoryServices.ActiveDirectory.Domain.GetDomain(context).GetDirectoryEntry(); 

然後,我有沒有問題訪問gecos屬性

相關問題