Volatile Registry Keys

Up until recently, I had never heard of a volatile registry key. I cam across a post by Daniel Moth that presents an extension method that adds support for both .NET and NETCF. While I haven't looked at the projects he provides, it did get me thinking about what this support would actually mean.

A volatile registry key is one whose information is stored only in memory and is not preserved when the corresponding registry hive is unloaded. For keys created under the HKEY_LOCAL_MACHINE hive, this occurs when the system is shutdown. For keys loaded by the RegLoadKey function, this occurs when the corresponding RegUnLoadKey is performed. To put it simply, this means that volatile registry keys do not survive a reboot.

At this point, you may be wondering why a volatile registry key would be useful. Normally, when you create a registry key for an application you want it persisted. However, there are times when you may want to store transient information in the registry. A volatile key would be perfect for this scenario since you don't have to worry about explicitly cleaning it up afterwards. Another scenario would be for use in build scripts, particularly scripts that build InstallShield projects. One feature of InstallShield is that you can create path variables that reference registry keys. This is useful in creating installer projects that are build server independent. If you create the required registry keys through the build script, you will probably be creating them each time the build script runs to ensure that they are always present and have the correct values. These registry keys are only important during the actual build process and, since they are recreated each time, don't really need to be persisted.

This article is part of the GWB Archives. Original Author: Scott Dorman

New on Geeks with Blogs

  • We Won The One Award I Actually Care About

    Full Scale made the Inc. 5000 for the fifth year straight, the 12th listing across my three companies. Here is why the one award you cannot buy is worth stopping for.

  • Your Customers Build the Features Now

    I let a tool I liked sit dead for a year rather than build the features I wanted. An MCP server meant I never had to, and your customers can do the same to your product.

  • Get the Size of a Directory in Linux the Easy Way

    du -sh for the quick answer, ncdu for the cleanup, df for the disk itself: every command for checking directory size in Linux, plus why du and df never agree.

  • Vim Search and Replace: The Ultimate Guide

    One :%s command replaces every match in a file before a find dialog would even open. The Vim substitute patterns worth the muscle memory: flags, ranges, capture groups, and multi-file edits.