共用方式為


設定屬性頁面上顯示的屬性

  • 本主題提供的程式碼範例可以設定在使用者的屬性頁面中顯示的屬性,這可以透過 [Active Directory 使用者和電腦] MMC 嵌入式管理單元存取。如果從未使用過這個嵌入式管理單元,請選取 [開始]、[所有程式]、[系統管理工具]、[Active Directory 使用者和電腦],以在伺服器上開啟它。在 [使用者] 資料夾中,以滑鼠右鍵按一下使用者名稱以顯示快顯功能表,並選取 [內容]。如果您正在設定可允許使用者變更資訊 (例如,住家地址) 的應用程式,可以將這段實用的程式碼加入到您的應用程式。

下列程式碼範例示範如何設定 [一般] 頁面中顯示的通用內容。

usr.Properties["givenName"].Value = "New User";
usr.Properties["initials"].Value = "Ms";
usr.Properties["sn"].Value = "Name";
usr.Properties["displayName"].Value = "New User Name";
usr.Properties["description"].Value = "Vice President-Operation";
usr.Properties["physicalDeliveryOfficeName"].Value = "40/5802";
usr.Properties["telephoneNumber"].Value = "(425)222-9999";
usr.Properties["mail"].Value = "newuser@fabrikam.com";
usr.Properties["wWWHomePage"].Value = "http://www.fabrikam.com/newuser";
usr.Properties["otherTelephone"].AddRange(new 
string[]{"(425)111-2222","(206)222-5263"});
usr.Properties["url"].AddRange(new 
string[]{"http://newuser.fabrikam.com","http://www.fabrikam.com/officers"});
usr.CommitChanges();

下列程式碼範例示範如何設定 [地址] 頁面中顯示的通用內容。

usr.Properties["streetAddress"].Value = "2050 Fabrikam Way NE";
usr.Properties["postOfficeBox"].Value = "S/2523";
usr.Properties["l"].Value = "Sammamish";
usr.Properties["st"].Value = "Washington";
usr.Properties["postalCode"].Value = "98074";
usr.Properties["c"].Value = "US";
usr.CommitChanges();

下列程式碼範例示範如何設定 [帳戶] 頁面中顯示的通用內容。

usr.Properties["userPrincipalName"].Value = "newuser@fabrikam.com";
usr.Properties["sAMAccountName"].Value = "newuser";
usr.Properties["userWorkstations"].Value = "wrkst01,wrkst02,wrkst03";
usr.CommitChanges();

新增或修改使用者物件上的特定存取控制項目,即可修改 [使用者不能變更密碼] 設定。如需 如需關於此作業的詳細資訊 (含示範做法的程式碼範例),請參閱管理使用者密碼

請參閱

參考

System.DirectoryServices

概念

使用者管理

Send comments about this topic to Microsoft.

Copyright © 2007 by Microsoft Corporation.All rights reserved.