共用方式為


ConfigurationSectionWithCollection.Remove 方法

從組態區段中的集合中移除指定的專案。

語法

ConfigurationSectionWithCollection.Remove collectionName, element;  
ConfigurationSectionWithCollection.Remove collectionName, element  

參數

名稱 定義
collectionName string值,指定要移除之專案的集合名稱。
element CollectionElement物件,其中包含要移除的專案。

傳回值

這個方法不會傳回值。

範例

下列範例會顯示預設網站的處理常式名稱,如果存在,則會移除名為 「CGI-exe」 的處理常式專案,然後再次列出處理常式名稱。 程式碼會導致下列 XML 新增至 <system.webServer> 預設網站的 Web.config 檔案區段:

<handlers>

<remove name="CGI-exe" />

</handlers>

' Connect to the WMI WebAdministration namespace.  
Set oWebAdmin = GetObject("winmgmts:root\WebAdministration")  
  
' Get the default Web site.  
Set oSite = oWebAdmin.Get("Site.Name='Default Web Site'")  
  
' Get the handlers section.  
oSite.GetSection "HandlersSection", oHandlersSection  
  
' Display the current handler names.  
Wscript.Echo "---[Current Handler List]---"  
Call DisplayHandlerNames  
  
' Remove the CGI-exe handler by matching its name.  
For Each oHandler In oHandlersSection.Handlers  
     If oHandler.Name = "CGI-exe" Then  
        oHandlersSection.Remove "Handlers", oHandler  
    End If   
Next  
  
' Refresh the oHandlersSection object so that its contents will  
' reflect the updated configuration.  
oHandlersSection.Refresh_      
  
' List the handler names again to show the change.  
Wscript.Echo "---[New Handler List]---"  
Call DisplayHandlerNames  
  
' Provide a subroutine to display handler names.  
Sub DisplayHandlerNames  
    For Each oHandler In oHandlersSection.Handlers  
        WScript.Echo "Handler Name: " & oHandler.Name  
    Next  
    Wscript.Echo  
End Sub  
  

注意Remove_呼叫 方法會更新基礎組態存放區,但不會 oHandlersSection 更新記憶體中執行的物件。 Refresh_在 上 oHandlersSection 呼叫 方法時,如果您需要稍後在相同的腳本中使用此方法,可確保其資料正確無誤。

規格需求

類型 描述
Client - Windows Vista 上的 IIS 7.0
- Windows 7 上的 IIS 7.5
- Windows 8 上的 IIS 8.0
- Windows 10上的 IIS 10.0
伺服器 - Windows Server 2008 上的 IIS 7.0
- Windows Server 2008 R2 上的 IIS 7.5
- Windows Server 2012 上的 IIS 8.0
- Windows Server 2012 R2 上的 IIS 8.5
- Windows Server 2016上的 IIS 10.0
產品 - IIS 7.0、IIS 7.5、IIS 8.0、IIS 8.5、IIS 10.0
MOF 檔案 WebAdministration.mof

另請參閱

ConfigurationSectionWithCollection 類別
HandlerAction 類別
HandlersSection 類別