Freigeben über


Adding Properties to Existing IIS ADSI Classes

You can use the following VBScript example code to add existing properties to existing ADSI classes by modifying the OptionalProperties list for a Class object.

To add a property, follow these steps:

  • Bind to the class in the IIS ADSI Schema you want to add a property to.

  • Bind to the OptionalProperties list for the Class object.

  • Add the new property to the list.

  • Write the new OptionalProperties list to the metabase.

Example Code

The following example shows you how to use the VBScript programming language to modify the OptionalProperties list for a Class object.

'   Get the parameters for the machine name. 
Dim MachineName 
Dim ClassName 
Dim PropertyName 
Dim Action 
Dim ArgObj 
Set ArgObj=WScript.Arguments 
Action = ArgObj.Item (0) 
MachineName = ArgObj.Item (1) 
ClassName = ArgObj.Item (2) 
PropertyName = ArgObj.Item (3) 

'   Bind to Class in Schema container. 
Dim SchemaObj 
Dim NewClassObj 
Set NewClassObj = GetObject ("IIS://" & MachineName & "/Schema/" & ClassName) 

'   Set the OptionalProperties list. 
'   Add PropertyName. 
Dim OptPropList 
Dim cntOptPropList = NewClassObj.OptionalProperties 
cnt = UBound(OptProplist) 
If (Action = "add") Then 
   ReDim Preserve OptPropList(cnt+1) 
   OptPropList(cnt+1) = PropertyNameNewClassObj.OptionalProperties = OptPropList 
End If 

if (Action = "del") Then 
   Dim temparraycount 
   ReDim temparraycount (cnt-1) 
   Dim tempcount1 
   Dim tempcount2tempcount1 = 0 
   tempcount2 = 0 

   do while (tempcount2 <= cnt) 
      If ( OptProplist(tempcount2) <> PropertyName) Then 
         temparraycount (tempcount1) = OptPropList (tempcount2) 
         tempcount1 = tempcount1 + 1 
      End If 
      tempcount2 = tempcount2 + 1 
   Loop 

   NewClassObj.OptionalProperties = temparraycount 
End if 

NewClassObj.SetInfo