Getting Data In and Out

There are several ways to move data into and out of the Registry; which one you use depends on what you’re trying to accomplish and the amount of time you’re willing to spend. Each of them is covered in more detail in later chapters.

First of all, you can make direct calls to the Win32 Registry API routines. At bottom, this is what all the other methods eventually do; the OS’ security components and the undocumented internal format of the hive files ensure that the only way to load data is to use these routines. The basic process is fairly simple: you start by opening a key or subkey by its name. Once you’ve done so, you can do things to that key or its subkeys: you can query its value, create new subkeys beneath it, or even ask about its security settings. You can continue to use that particular key until you’re done it, at which time you must close it again. Here’s a small sample that shows these steps in action; it gets the computer’s network name and uses it to print a welcome message. You’ll learn more about programming for the Registry in C (as in this example) in the section titled Programming with C/C++ in Chapter 8.

// Hello, World! for the Registry: gets this machine's name and prints // it out. #include <windows.h> #include <winreg.h> #include <stdio.h> void main(void) { unsigned char lpName[MAX_PATH] = ""; DWORD nNameLen = MAX_PATH; HKEY hkResult, hStartKey = HKEY_LOCAL_MACHINE; LONG nResult = ERROR_SUCCESS; nResult = RegOpenKeyEx(hStartKey, ...

Get Managing The Windows 2000 Registry 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.