How can I use a variable in custom inventory registry path?
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:
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:
<%foreach regkey="prodguid" path="%path%"%>
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:
- The "reg" keyword, which tells custinv to return a key's value.
- The '%path% variable which holds the initial path.
- The key:prodguid.%keyname% variable for the name of the current subdirectory in the registry path.
- The remainder of the path.
- 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?"
Rate this Article