How can I use a variable in custom inventory registry path?

Article:HOWTO9242  |  Created: 2005-12-02  |  Updated: 2009-11-04  |  Article URL http://www.symantec.com/docs/HOWTO9242
Article Type
How To


Question
How can I use a variable in custom inventory registry path?

Answer
The Windows registry has many entries with identical structure except for a slight difference in the paths. For example, the Products\InstallProperties entries have identical keys, such as DisplayName, RegCompany, RegOwner, etc. But, each has a unique GUID in the path, as seen here:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\042E9802C33BD814D958BB373397E38C\InstallProperties
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\064D6CDC91DE87E42AC70F66F1CF7D6A\InstallProperties

Note: The only difference in the above paths is the GUID between "Products" and "InstallProperties".

To simplify the retrieval of data using custom inventory in a situation such as this, it is possible to include a variable in the path rather than hard-code each path individually, as shown in this segment of a custom inventory script:

<rs:data>  
<%set path="HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\"%>
<%set pathb="InstallProperties"%>

<%foreach regkey="prodguid" path="%path%"%>
        <z:row     
             c0="<%writexml "key:prodguid.%keyname%"%>"     
             c1="<%writexml "reg:%path%key:prodguid.%keyname%\%pathb%\DisplayName"%>"
             c2="<%writexml "reg:%path%key:prodguid.%keyname%\%pathb%\RegCompany"%>"
             c3="<%writexml "reg:%path%key:prodguid.%keyname%\%pathb%\RegOwner"%>"      
        /> 
<%next%>
 </rs:data>

The initial portion of the path is placed into the 'path' variable. The final portion of the path is placed into the "pathb" variable.

The "foreach" loop then traverses each entry in the initial path, setting the variable "prodguid" to the name of the current subdirectory. In other words, we loop through each product, setting prodguid to the value of the product guid in the registry path.

The "c1" line contains:

  1. The "reg" keyword, which tells custinv to return a key's value.
  2. The '%path% variable which holds the initial path.
  3. The key:prodguid.%keyname% variable for the name of the current subdirectory in the registry path.
  4. The remainder of the path.
  5. The key whose value is to be retrieved.

Note: The slashes are necessary to form a valid registry path.

A complete example can be found at KB article 4237

The name of the file is: var_in_reg_path.xml.

Another option is to use the recurse parameter in the foreach loop. See article 23929, "How do I recurse multiple registry keys with custom Inventory for Windows?"



Legacy ID



4308


Article URL http://www.symantec.com/docs/HOWTO9242


Terms of use for this information are found in Legal Notices