Reading a Multistring-valued Entry

Microsoft® Windows® 2000 Scripting Guide

microsoft windows 2000 scripting guide

« Previous | Next »   

A multistring value stores a list of strings. A typical use of a multistring value is demonstrated by the Autorecover MOFs entry in the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\WBEM\CIMOM subkey. This entry holds a list of .mof files that are used to autorecover the CIM repository. The list could have been held in a series of string-valued entries, all stored under a single Autorecover MOFs subkey. However, using a multistring value is more compact and makes programmatic retrieval of the values more convenient. With a multistring entry, there is only one registry entry to read, which makes it more likely that you will retrieve every value. By contrast, storing each value in a separate registry entry requires you to individually read each of those entries. In turn, that increases the likelihood of you missing a value.

Figure 16.3 shows how a registry editor displays a multistring value. You can see that it is simply a list of strings contained under the single Autorecover MOFs entry.

Figure 16.3   Multistring Value as Displayed by a Registry Editor

Multistring Value as Displayed by a Registry Editor

You use the GetMultiStringValue method to retrieve a multistring value. The method takes as one of its parameters a variable that holds the set of strings retrieved. The strings are returned in an array, so you must use a For Each loop in your script to enumerate each of the individual strings in the array.

Scripting Steps

Listing 16.4 contains a script that retrieves a multistring value from the registry. 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 path of the registry subkey in which the value is located.
  5. Create a variable and set it to the name of the entry.
  6. Use the GetMultiStringValue method to retrieve the array of string values.
  7. For each string value in the array, echo the value to the screen.

Listing 16.4   Reading a Multistring-valued Entry

1 2 3 4 5 6 7 8 9 10 11 12 13 14 
Const HKEY_LOCAL_MACHINE = &H80000002 strComputer = "." Set objReg=GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & _      strComputer & "\root\default:StdRegProv") strKeyPath = "SOFTWARE\Microsoft\WBEM\CIMOM" strValueName = "Autorecover MOFs" objReg.GetMultiStringValue HKEY_LOCAL_MACHINE,strKeyPath, _     strValueName,arrValues For Each strValue In arrValues     Wscript.Echo  strValue Next

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