ConfigurationSectionWithCollection.Remove メソッド

構成セクションのコレクションから指定した要素を削除します。

構文

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

Parameters

名前 Definition
collectionName 削除する要素があるコレクションの名前を指定する string 値。
element 削除する要素を含む CollectionElement オブジェクト。

戻り値

このメソッドは値を返しません。

次の例では、既定 Web サイトのハンドラーの名前を表示し、"CGI-exe" という名前のハンドラー要素が存在する場合は削除してから、ハンドラー名をもう一度一覧表示します。 このコードにより、既定 Web サイトの Web.config ファイルの <system.webServer> セクションに次の XML が追加されます。

<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 オブジェクトは更新されません。 oHandlersSectionRefresh_ メソッドを呼び出すと、後で同じスクリプトで使用する必要がある場合に、そのデータが正確であることが確実になります。

要件

説明
クライアント - 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
Product - IIS 7.0、IIS 7.5、IIS 8.0、IIS 8.5、IIS 10.0
MOF ファイル WebAdministration.mof

参照

ConfigurationSectionWithCollection クラス
HandlerAction クラス
HandlersSection クラス