设置在属性页上显示的属性

  • 本主题提供一些代码示例,用于为用户设置属性页上显示的属性,可以通过 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.

版权所有 (C) 2007 Microsoft Corporation。保留所有权利。