Modifying the Properties of an Instance

In some cases, you will want to adjust the properties of a particular component once it has been added to the runtime. However, this process is not very intuitive. When you create an Instance and store it to a variable, as shown in the first example above, the Instance does not become initialized until after you add it to the configuration's Instances list. Therefore, you cannot edit the Instance's properties without first adding it to the runtime. Once it has been added, both the separate variable you created and the reference to that Instance in the configuration's list of Instances, point to the same object. Therefore, if you make a change to one, the change will be reflected in the other as well.

A common task that really makes use of this functionality is when adding multiple user accounts to a runtime. The following example shows how to do this.

xpecmd> load cfg "c:\myimages/image.slx"            (Load the configuration from disk)
xpecmd> new myUser Instance                        (Declare a new Instance variable)
xpecmd> myUser = 'inst:^User Account'               (Create a new Instance of User Account and store it in the variable)
xpecmd> cfg.Instances.Add myUser                     (Add this Instance to the runtime. This initializes the Instance)
xpecmd> myUser.Properties("cmiUserName") = "Matt"   (Set the Instance's UserName property)
xpecmd> myUser.Properties("cmiUserGroup") = 1      (Make this user an administrator)
xpecmd> myUser = 'inst:^User Account'               (Create another new Instance. This does not affect the first account)
xpecmd> cfg.Instances.Add myUser                     (Add this Instance to the runtime as User Account #2)
xpecmd> myUser.Properties("cmiUserName") = "John"   (Set the second account's name to "John")
xpecmd> myUser.Properties("cmiUserGroup") = 2      (Make this user a Power User)

The preceding example adds two separate User Accounts to the runtime, "Matt" as an administrator and "John" as a Power User.

Setting multistring properties requires a special syntax:

myInst.Properties("PropertyName") = Array("value1","value2",...)

For example, the following XPECMD script modifies Enhanced Write Filter multistring properties:

xpecmd> initcfg mycfg (Initialize configuration)
xpecmd> new myInst = 'inst:Enhanced Write Filter' (Create a new Instance of the EWF component)
xpecmd> mycfg.add myInst (Add this Instance to the configuration and initialize the Instance)
xpecmd> myInst.Properties("PVType") = Array("2") (Set "RAM Reg" mode for the first protected volume)
xpecmd> myInst.Properties("EwfEnable") = Array("0") (Disable EWF on start for the first protected volume)

To see a list of the available properties for an Instance after you've added it to the configuration, use the show or dump commands, as shown in the following examples.

xpecmd> show myUser.Properties
xpecmd> dump myUser.Properties

To edit an existing property, refer to the property's name in quotes. The following example shows how to do this.

xpecmd> myUser.Properties("cmiUserName") = "Matt"

Last updated on Wednesday, October 18, 2006

© 2006 Microsoft Corporation. All rights reserved.