Creating Multistring-valued Entries

Microsoft® Windows® 2000 Scripting Guide

microsoft windows 2000 scripting guide

« Previous | Next »   

Multistring-valued registry entries are relatively rare in the registry. The Registry Provider does, however, provide the SetMultiStringValue method to enable you to create these entries as needed. Because a multistring can store a list of strings, the SetMultiStringValue method accepts an array of strings as the parameter that determines the values of the entry.

Note that if you use the SetMultiStringValue method to append to an existing multistring-valued entry rather than create a new one, you have to first use the GetMultiStringValue method to retrieve the existing list of strings. This is because SetMultiStringValue overwrites any existing value. For example, suppose you have a multistring value consisting of the following strings:

A B C D 

If you use the SetMultiStringValue method, you cannot pass the string "E" as the sole parameter; if you do, the A, B, C, and D strings will be replaced, and the entry will contain this value:

E 

To append "E" as an additional string within the value, you must pass an array containing the initial string values as well as the new value:

arrStringValues = Array("A", "B", "C", "D", "E") objReg.SetMultiStringValue HKEY_LOCAL_MACHINE,strKeyPath, _     strEntryName,arrStringValues 

Scripting Steps

Listing 16.10 contains a script that creates a multistring-valued entry in the registry subkey created by the script in Listing 16.8. To carry out this task, the script must perform the following steps:

  1. Create a constant that holds the hexadecimal number corresponding to the HKEY_LOCAL_MACHINE subtree.
  2. Create a variable and set it to the computer name.
  3. Use a GetObject call to connect to the WMI namespace root\default, and set the impersonation level to "impersonate."
  4. Create a variable and set it to the subkey in which the entries will be created.
  5. Create a variable and set it to the name of the string-valued registry entry being created.
  6. Create an array variable in which to specify the multiple strings that will make up the multistring value of the registry entry being created.
  7. Use the SetMultiStringValue method to create the new multistring-valued entry.

Listing 16.10   Creating Registry Multistring-valued Entries

1 2 3 4 5 6 7 8 9 10 11 12 13 
Const HKEY_LOCAL_MACHINE = &H80000002 strComputer = "." Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _      strComputer & "\root\default:StdRegProv") strKeyPath = "SOFTWARE\System Admin Scripting Guide" strEntryName = "Multi String Value Name" arrStringValues = Array("first string", "second string", _    "third string", "fourth string") objReg.SetMultiStringValue HKEY_LOCAL_MACHINE,strKeyPath, _     strEntryName,arrStringValues

Figure 16.6 shows the newly created multistring-valued entry in a registry editor.

Figure 16.6   Newly Created Multistring-valued Entry

Newly Created Multistring-valued Entry


send us your feedback Send us your feedback « Previous | Next »   


Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 635

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net