Getting Registry Keys and Values

The cfregistry tag gives you two methods for retrieving keys and values from the registry. You can set the action attribute to GetAll to retrieve all the particular keys/values associated with a particular branch, or you can set action="Get" to retrieve the value associated with a specific entry.

Let’s consider a scenario where we want to look up information about any ODBC data sources set up on the same machine as ColdFusion. There is a registry branch we can access that contains this information. The branch is:

HKEY_LOCAL_MACHINE\Software\ODBC\ODBC.INI

It contains a list of every ODBC data source registered on the system. Each key contains several other subkeys relating to the ODBC connection. Example 25-1 shows how to perform the registry lookup.

Example 25-1. Retrieving a list of registry keys

<cfregistry action="GetAll" branch="HKEY_LOCAL_MACHINE\Software\ODBC\ODBC.INI"
            name="GetODBC" type="Key" sort="Entry Asc">
 
<h3>HKEY_LOCAL_MACHINE\Software\ODBC\ODBC.INI</h3>
 
<table border="1">
<tr>
  <th>Entry</th><th>Type</th><th>Value</th>
</tr>
 
<cfoutput query="GetODBC">
<tr>
  <td>#Entry#</td><td>#Type#</td><td>#Value#</td>
</tr>
</cfoutput>
</table>

In Example 25-1, we set the action attribute of the cfregistry tag to GetAll. This action results in ColdFusion retrieving all the registry keys and values that fall under the branch specified in branch. The name attribute allows us to specify a name for the query object that holds all the information we ...

Get Programming ColdFusion MX, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.