重新命名物件
DirectoryEntry 提供 Rename 方法來重新命名目錄中的物件。
下列範例示範如何使用 Rename 來變更 User 物件的名稱。
Try
' Bind to the user object to modify.
Dim child As New DirectoryEntry("LDAP://CN=My User Name,OU=Marketing,DC=fabrikam,DC=com")
' Rename the object to Jeff Smith.
child.Rename("CN=New User Name")
Catch COMEx As COMException
' If a COMException is thrown, then the following code can capture the text of the error.
' For instructions about handling COM exceptions, see Handling Errors.
Console.WriteLine(COMEx.ErrorCode)
End Try '}
try
{
// Bind to the user object to modify.
DirectoryEntry child = new DirectoryEntry("LDAP://CN=My User Name,OU=Marketing,DC=fabrikam,DC=com");
// Rename the object to Jeff Smith.
child.Rename("CN=New User Name");
}
catch (COMException COMEx)
{
// If a COMException is thrown, then the following code can capture the text of the error.
// For more information about handling COM exceptions, see Handling Errors.
Console.WriteLine(COMEx.ErrorCode);
)
請參閱
參考
System.DirectoryServices
DirectoryEntry
概念
Send comments about this topic to Microsoft.
Copyright © 2007 by Microsoft Corporation.All rights reserved.