Sample Program

You can use the IIS Admin Objects to recursively walk the metabase on your computer. The following sample program uses VBScript code in an .asp file to list the nodes in the metabase structure, optionally printing the ADSI properties, mandatory properties, optional properties, whether each property is inheritable, and the data type of the property.

<HTML> 
<HEAD> 
<TITLE>SchemaA.asp (IIS Property Schema)</TITLE> 
</HEAD> 
<BODY BGCOLOR=#FFFFFF> 
<FONT FACE="Courier" SIZE=2> 
<% 
' This program will list metabase nodes installed on LocalHost, 
' optionally printing ADSI properties, mandatory properties, 
' optional properties, whether the properties are inheritable,
' and the data type of the property. 
 
' Option usage .../SchemaA.asp?ShowProp={param}&ShowInh={T|F} 
'     &ShowType={T|F}&StartKey={Path}&Recurse={T|F} 
' ShowProp={All|None|(one or more of AMO)} 
'   All or AMO => All properties [Default] 
'   None or N => No properties 
'   A => ADSI properties 
'   M => Mandatory properties 
'   O => Optional properties 
' ShowInh={T|F} (Show property inheritance attribute} 
' ShowType={T|F} (Show property data type) 
' StartKey={Path of starting key e.g. IIS://LocalHost/W3SVC} 
' Recurse={T|F} (Recurse from the starting key) 
' Default: All, T, T, IIS://LocalHost, T 
 
Dim MachName      ' Holds machine name (LocalHost) 
Dim ADsObj        ' Holds object 
Dim SchemaPath    ' Path to object's schema object 
Dim SchemaObj     ' Holds object's schema object 
Dim PropSchemaObj ' Holds schema for individual property 
Dim MandPropList  ' Holds object's mandatory property list 
Dim OptPropList   ' Holds object's optional property list 
 
Dim Level         ' Recursive indent level 
Dim LevelWidth    ' Number of indent spaces per level (default 3) 
Dim Indent        ' String spaces for indentation 
Dim ShowProp      ' Input parameter 
Dim ShowInh       ' Input parameter 
Dim StartKey      ' Input parameter 
Dim Recurse       ' Input parameter 
Dim PropArgs      ' Temporary variable 
Dim InhArgs       ' Temporary variable 
Dim KeyArgs       ' Temporary variable 
Dim RecurseArgs   ' Temporary variable 
 
Dim InhList(2)    ' Holds output text 
InhList(0) = "  Inh  " 
InhList(1) = "Not Inh" 
InhList(2) = "Invalid Property" 
 
MachName = "LocalHost" 
 
' Get arguments from command line 
ShowProp = "AMO"  ' Default to all options 
PropArgs = Request.QueryString("ShowProp") 
If PropArgs <> "" Then 
    ShowProp = UCase(PropArgs) 
    If ShowProp = "NONE" Then ShowProp = "N" 
    If ShowProp = "ALL" Then ShowProp = "AMO" 
End If 
 
ShowInh = "T" 
InhArgs = Request.QueryString("ShowInh") 
If InhArgs <> "" Then 
    ShowInh = UCase(InhArgs) 
    If ShowInh = "YES" or ShowInh = "TRUE" Then ShowInh = "T" 
    If ShowInh = "FALSE" or ShowInh = "F" Then ShowInh = "F" 
End If 
 
ShowType = "T" 
InhArgs = Request.QueryString("ShowType") 
If InhArgs <> "" Then 
    ShowType = UCase(InhArgs) 
    If ShowType = "YES" or ShowType = "TRUE" Then ShowType = "T" 
    If ShowType = "FALSE" or ShowType = "F" Then ShowType = "F" 
End If 
 
StartKey = "IIS://" & MachName 
KeyArgs = Request.QueryString("StartKey") 
If KeyArgs <> "" Then 
    StartKey = KeyArgs 
End If 
 
Recurse = "T" 
RecurseArgs = Request.QueryString("Recurse") 
If RecurseArgs <> "" Then 
    Recurse = UCase(RecurseArgs) 
End If 
 
on error resume next 
Set ADsObj = GetObject(StartKey) 
If err.number <> 0 then 
    response.write "Error " & err.number & "  =  " & err.description 
    Err.Raise ,,"Unable to open path object" 
end if 
 
REM Use HTML <PRE> tag to prevent white space compression 
Response.Write "<PRE>" 
 
Response.Write "<B>" & ADsObj.ADsPath & "</B>  Structure/Property Schema</B><BR>" 
Response.Write "    [ShowProp = " & ShowProp & "]<BR>" 
Response.Write "    [ShowInh  = " & ShowInh & "]<BR>" 
Response.Write "    [ShowType = " & ShowType & "]<BR>" 
Response.Write "    [StartKey = " & StartKey & "]<BR>" 
Response.Write "    [Recurse  = " & Recurse & "]<BR>" 
 
Response.Write "<BR>" 
Response.Write " <B>Option usage:</B> .../SchemaA.asp?ShowProp={param}&ShowInh={T|F}" 
Response.Write "&ShowType={T|F}&StartKey={Path}&Recurse={T|F} <BR>" 
Response.Write "   ShowProp={All|None|(one or more of AMO)}  <BR>" 
Response.Write "     All or AMO => All properties [Default]  <BR>" 
Response.Write "     None or N => No properties  <BR>" 
Response.Write "     A => ADSI properties  <BR>" 
Response.Write "     M => Mandatory properties  <BR>" 
Response.Write "     O => Optional properties  <BR>" 
Response.Write "   ShowInh={T|F} (Show property inheritance attribute}  <BR>" 
Response.Write "   ShowType={T|F} (Show property data type)  <BR>" 
Response.Write "   StartKey={Path of starting key e.g. IIS://LocalHost/W3SVC}  <BR>" 
Response.Write "   Recurse={T|F} (Recurse from the starting key)  <BR>" 
Response.Write "   Default: All, T, T, IIS://LocalHost, T  <BR>" 
 
Response.Write "<HR>" 
 
' Recursively retrieve and print object names and properties 
LevelWidth = 3 
Level = -1 
PrintProps(ADsObj) 
 
' Complete the page 
Response.Write "</PRE>" 
Response.Write "<HR>" 
 
Sub PrintProps(ThisObj) 
On error Resume next 
If Err.Number <> 0 Then 
    Err.Clear 
    Level = Level - 1 
    Exit Sub 
End If 
Level = Level + 1 
Response.write Space(LevelWidth*Level) 
If ShowProp <> "N" Then 
    Response.write "<B>" 
End If 
Response.Write ThisObj.Name 
If IsNumeric(ThisObj.Name) Then 
    Response.write " (Virtual Server - " & ThisObj.ServerComment & ")" 
End If 
If ShowProp <> "N" Then 
    Response.write "</B>" 
End If 
Response.Write "<BR>" 
 
If Instr(ShowProp, "A") > 0 Then 
    ' Print the ADSI properties 
    Indent = Space(LevelWidth*(Level+1)) 
    Response.Write Indent & "<I>ADSI Properties</I><BR>" 
    Indent = Space(LevelWidth*(Level+2)) 
    Response.write Indent & "Name    = " & ThisObj.Name 
    Response.write "<BR>" 
    Response.write Indent & "ADsPath = " & ThisObj.AdsPath 
    Response.write "<BR>" 
    Response.write Indent & "Class   = " & ThisObj.Class 
    Response.write "<BR>" 
    Response.write Indent & "GUID    = " & ThisObj.GUID 
    Response.write "<BR>" 
    Response.write Indent & "Parent  = " & ThisObj.Parent 
    Response.write "<BR>" 
    Response.write Indent & "Schema  = " & ThisObj.Schema 
    Response.write "<BR>" 
End If  ' Show ADSI 
 
If Instr(ShowProp, "M") > 0 Then 
    ' Print the mandatory properties 
    SchemaPath = ThisObj.Schema 
    Set SchemaObj = GetObject(SchemaPath) 
    Indent = Space(LevelWidth*(Level+1)) 
    Response.Write Indent & "<I>Mandatory Properties</I><BR>" 
    MandPropList = SchemaObj.MandatoryProperties 
    Indent = Space(LevelWidth*(Level+2)) 
    For Each PropName in MandPropList 
        Response.Write Indent & PropName 
        If ShowInh = "T" Then 
            Response.Write Space(35-Len(PropName)) 
            Response.Write InhList(IsInheritable(PropName)) 
        End If 
        If ShowType = "T" Then 
            If ShowInh = "T" Then 
                ' Already vertically aligned - just move on a little 
                Response.Write Space(4) 
            Else 
                ' Pad out to align vertically 
                Response.Write Space(35-Len(PropName)) 
            End If 
            Set PropSchemaObj = GetObject("IIS://" & MachName & "/Schema/" & PropName) 
            Response.Write PropSchemaObj.Syntax 
        End If 
        Response.Write "<BR>" 
    Next 
    End If   ' Show Mandatory 
 
If Instr(ShowProp, "O") > 0 Then 
    ' Print the optional properties 
    SchemaPath = ThisObj.Schema 
    Set SchemaObj = GetObject(SchemaPath) 
    Indent = Space(LevelWidth*(Level+1)) 
    Response.Write Indent & "<I>Optional Properties</I><BR>" 
    OptPropList = SchemaObj.OptionalProperties 
    Indent = Space(LevelWidth*(Level+2)) 
    For Each PropName in OptPropList 
        Response.Write Indent & PropName 
        If ShowInh = "T" Then 
            Response.Write Space(35-Len(PropName)) 
            Response.Write InhList(IsInheritable(PropName)) 
        End If 
        If ShowType = "T" Then 
            If ShowInh = "T" Then 
                ' Already vertically aligned - just move on a little 
                Response.Write Space(4) 
            Else 
                ' Pad out to align vertically 
                Response.Write Space(35-Len(PropName)) 
            End If 
            Set PropSchemaObj = GetObject("IIS://" & MachName & "/Schema/" & PropName) 
            Response.Write PropSchemaObj.Syntax 
        End If 
        Response.Write "<BR>" 
    Next 
End If   ' Show Optional 
 
' Enumerate children recursively 
If Recurse <> "T" Then 
    Exit Sub 
End If 
If ShowProp <> "N" Then    ' Add a blank separator line if props show 
    Response.Write "<BR>" 
End If 
For Each Child in ThisObj 
    If Err.Number <> 0 Then 
        ' Skip objects that have no children 
        Err.Clear 
    Else 
        ' Recurse into the children of this object 
        PrintProps(Child) 
    End If 
Next 
Level = Level - 1 
Err.Clear 
End Sub 
 
Function IsInheritable(PropNameIn) 
' Returns 0 if inheritable 
' Returns 1 if a valid property and not inheritable 
' Returns 2 if not a valid property 
Const IIS_INHERITABLE_ONLY = 1 
Const MD_ERROR_DATA_NOT_FOUND = &H800CC801 
Const NOT_A_VALID_PROPERTY = &H80005006 
Dim IsInheritableObj 
Dim IsInheritablePaths 
On Error Resume Next 
Set IsInheritableObj = GetObject("IIS://" & MachName) 
IsInheritablePaths = IsInheritableObj.GetDataPaths(PropNameIn, IIS_INHERITABLE_ONLY) 
Select Case Err.Number 
    Case 0                        ' Valid property, inheritable 
        IsInheritable = 0 
    Case MD_ERROR_DATA_NOT_FOUND  ' Valid property, not inheritable 
        IsInheritable = 1 
    Case NOT_A_VALID_PROPERTY     ' Not a valid property 
        IsInheritable = 2 
End Select 
Err.Clear 
End Function 
 
%> 
</BODY> 
</HTML>