刪除目錄物件

為了移除目錄物件,DirectoryEntries 類別提供 Remove 方法。此方法會從目前父代 DirectoryEntry 物件的 Children 集合移除子項目。此方法只能用於空容器或不作為目錄樹狀目錄之容器的物件,例如印表機或電腦節點。如需有關刪除具有子物件之容器的詳細資訊,請參閱刪除物件的子樹狀結構

下列範例示範如何從目錄移除物件。

Dim entry As New DirectoryServices.DirectoryEntry("WinNT://DomainName")
Dim entryToRemove As DirectoryServices.DirectoryEntry

' Add code here to set entryToRemove to the entry you want to remove.
entry.Children.Remove(entryToRemove)
System.DirectoryServices.DirectoryEntry entry = 
   new System.DirectoryServices.DirectoryEntry("WinNT://DomainName");
System.DirectoryServices.DirectoryEntry entryToRemove = null;

// Add code here to set entryToRemove to the entry you want to remove.
entry.Children.Remove(entryToRemove);

請參閱

參考

System.DirectoryServices
DirectoryEntry
DirectoryEntries

概念

建立、刪除、重新命名和移動物件
刪除物件的子樹狀結構

Send comments about this topic to Microsoft.

Copyright © 2007 by Microsoft Corporation.All rights reserved.