O'Reilly logo

Managing The Windows 2000 Registry by Paul Robichaux

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Programming with C/C++

The API examples and documentation in earlier sections all present the Registry API in its native C/C++ form. Since many administrators are comfortable with C and/or C++, I’ll start the programming examples by presenting three distinct uses for the Registry API routines I’ve already presented.

Example: Watching a Key for Changes

RegNotifyChangeKeyValue is a little-used, but very useful, routine. It’s only present in Windows 2000 and NT, which perhaps accounts for its relative anonymity. If you need to be notified when a key or its values changes, it’s the best tool for getting you that notification. WatchKey, shown in Example 8-4, is a small utility that takes advantage of RegNotifyChangeKeyValue to warn you when a key you specify has been changed.

How the code works

After a check of its initial command-line arguments, the code performs the following steps:

  1. It identifies which root key “owns” the key you want to monitor; this is required because RegOpenKeyEx needs an already open key (i.e., one of the roots) to open the target key. If it can’t figure out which root the user specified, it prints an error and exits.

  2. It captures the pathname of the key to monitor and uses it, along with the root key, to call RegOpenKeyEx. The key is opened with KEY_READ access, which includes KEY_NOTIFY access too. If the key can’t be opened, the code generates an error message and exits.

  3. The target key is monitored with a call to RegNotifyChangeKeyValue. The code passes ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required