共用方式為


Accessing and Using Metabase Schema Information

It is possible to use ADSI to read the IIS metabase schema to determine the data type for a property or to determine what properties can be set at a certain node. This is different from enumerating properties that are set in the metabase because all possible properties might not exist at that node if they are not explicitly set.

Example Code

These examples were taken from the %SystemDrive%\Inetpub\AdminScripts\AdsUtil.vbs tool. AdsUtil.vbs contains more functionality and extensive error checking code that was not included in these samples in order to emphasize their purpose.

The following example code shows you how to use the VBScript programming language to determine the data type of a property.

This example uses ADSI.

IIsSchemaPath = "IIS://localhost/Schema/WAMUserPass" 
Set IIsSchemaObject = GetObject(IIsSchemaPath) 

If (Err.Number <> 0) Then 
  WScript.Echo "Error Trying To GET the Schema of the property: " & IIsSchemaPath 
  WScript.Quit (Err.Number) 
End If 

ObjectDataType = UCase(IIsSchemaObject.Syntax) 
WScript.Echo("Data type of " & IIsSchemaPath & " is " & ObjectDataType)

The following example code shows you how to use the VBScript programming language to enumerate all available properties at a metabase node.

This example uses ADSI.

Dim PropertyListSet 
Dim ADSIPath 
ADSIPath = "IIS://localhost/w3svc" 
Set IIsObject = GetObject(ADSIPath) 

' Get the Schema of the object and enumerate through all of the properties 
IIsSchemaPath = IIsObject.Schema 
Set IIsSchemaObject = GetObject(IIsSchemaPath) 

If (Err.Number <> 0) Then 
  WScript.Echo 
  WScript.Echo "Error Trying To GET the Schema of the class: " & IIsSchemaPath 
  WScript.Quit (Err.Number) 
End If 

ReDim PropertyListSet(1) 
PropertyListSet(0) = IIsSchemaObject.MandatoryProperties 
PropertyListSet(1) = IIsSchemaObject.OptionalProperties 

If (Err.Number <> 0) Then 
WScript.Echo 
ReportError () 
WScript.Echo "Error trying to get the list of properties: " & IIsSchemaPath 
WScript.Quit (Err.Number) 
End If 

WScript.Echo 
WScript.Echo("Available properties at " & ADSIPath) 
WScript.Echo("-----------------------------------") 
For Each PropertyList In PropertyListSet 
  'WScript.Echo("In " & PropertyList) 
  For Each PropertyName In PropertyList 
    WScript.Echo(PropertyName) 
  Next 
Next