共用方式為


ConfiguredObject.GetSection 方法

擷取已設定物件的組態區段內容。

語法

ConfiguredObject.GetSection(SectionName, Section);  
ConfiguredObject.GetSection SectionName, Section  

參數

名稱 描述
SectionName 變數 string ,其中包含要 (擷取的組態區段名稱,例如「BasicAuthenticationSection」) 。
Section ConfigurationSection變數,在其中放置組態區段的內容。

傳回值

這個方法不會傳回值。

備註

您可以使用 GetSection 方法來擷取所需組態區段的內容,並設定其可設定的屬性。

注意

方法 GetSection 簽章包含 [IN] 區段名稱的參數,以及 [OUT] 方法傳回之區段物件的參數。

範例

下列範例會取得預設網站的 HTTP 錯誤區段,並同時顯示其陣列和非陣列屬性。

' 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 HTTP errors section by using the GetSection method.  
oSite.GetSection "HttpErrorsSection", oSection  
  
' Display a heading.  
WScript.Echo "=============================="  
WScript.Echo "Http Errors Section Properties"  
WScript.Echo "=============================="  
  
' Display the HttpErrorsSection non-array properties.  
For Each vProp In oSection.Properties_  
    If (vProp.Name <> "HttpErrors") And _  
        (vProp.Name <> "SectionInformation") Then  
        WScript.Echo vProp.Name & ": " & vProp.Value  
    End If  
Next  
WScript.Echo   
  
' Display the HttpErrorsSection SectionInformation properties.  
WScript.Echo "HttpErrorsSection.SectionInformation"  
WScript.Echo "------------------------------------"  
For Each vProp In oSection.SectionInformation.Properties_  
    WScript.Echo vProp.Name & ": " & vProp.Value  
Next  
WScript.Echo  
  
' Display the contents of the HttpErrors array property.  
WScript.Echo "HttpErrorsSection.HttpErrors"  
WScript.Echo "----------------------------"  
For Each oHttpErrorElement In oSection.HttpErrors  
    For Each vProp In oHttpErrorElement.Properties_  
        WScript.Echo vProp.Name & ": " & vProp.Value  
    Next  
    WScript.Echo  
Next  
  

規格需求

類型 描述
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

另請參閱

ConfigurationSection 類別
ConfiguredObject 類別
HttpErrorElement 類別
HttpErrorsSection 類別