Introduction


The registry is the primary repository for system, application, and user profile configuration information for the Windows operating system. It is a hierarchical database that is structured and used much like a filesystem. The operating system uses the registry to store information as static as environment variables and as dynamic as performance data. The registry is constantly being used by the OS and applications to read, write, and query configuration settings.

Don't Be Scared of the Registry

You have probably seen this warning or one similar to it in an article, book, or Microsoft KB article:

WARNING: If you use Registry Editor incorrectly, you may cause serious problems that may require you to reinstall your operating system. Microsoft cannot guarantee that you can solve problems that result from using Registry Editor incorrectly. Use Registry Editor at your own risk.

I think this type of warning has made some people overly cautious about modifying or even browsing the registry. I'm here to say that it doesn't have to be that way. Sure, you can muck up the registry, just like you can muck up the operating system or just about any application if you haphazardly delete or modify things. But you are a reasonable person that won't go around making changes on a production system unless you know the impact, so let's put concerns about modifying the registry behind us and move forward. Use the registry as a great source of configuration information and a mechanism to customize the operating system.


Using a Graphical User Interface

Windows 2000 came with two graphical registry editors that had different benefits. The first (regedit.exe) was more user-friendly, had better search capabilities, and was easy to work with while the other (regedt32.exe) was much more powerful. In Windows Server 2003, most of the features of these two tools were combined into a single tool. Now, Registry Editor has the same look and feel as the user-friendly version in Windows 2000 (regedit.exe), but also incorporates some important features such as permission editing from regedt32.exe. If you run either regedit.exe or regedt32.exe, you'll bring up the same tool.

One other graphical tool you should be familiar with is Registry Monitor (regmon.exe) from Sysinternals. With it, you can view all of the registry activity on a system in real-time. You can restrict the output to a certain key, and limit the type of activity (read, write, etc.). I cover Registry Monitor in more detail in Recipe 9.12.

Using a Command-Line Interface

The one command-line tool I use extensively throughout this chapter is reg.exe. In Windows 2000, reg.exe could be found in the Support Tools, but it comes installed by default with Windows Server 2003. With it, you can:

  • Search the registry

  • Add, modify, and delete registry keys and values

  • Import, export, and compare registry files

Using VBScript

WMI has a single class called StdRegProv that provides most of the functions you'll need to programmatically manage the registry. Table 9-1 lists the methods available with this class. This class is a little different from most others in that it doesn't contain properties for object instances (keys, values, etc.). To obtain information about a registry key or value, you have to use one of the methods shown in Table 9-1.

Table 9-1. StdRegProv methods

Method

Description

CheckAccess

Determines if a user has the specified permissions on a registry key

CreateKey

Creates a key

DeleteKey

Deletes a key

DeleteValue

Deletes a value

EnumKey

Enumerates the subkeys of a key

EnumValues

Enumerates the values of a key

GetBinaryValue

Retrieves data from REG_BINARY value

GetDWORDValue

Retrieves data from REG_DWORD value

GetExpandedStringValue

Retrieves data from REG_EXPAND_SZ value

GetMultiStringValue

Retrieves data from REG_MULTI_SZ value

GetStringValue

Retrieves data from REG_SZ value

SetBinaryValue

Sets data for REG_BINARY value

SetDWORDValue

Sets data for REG_DWORD value

SetExpandedStringValue

Sets data for REG_EXPAND_SZ value

SetMultiStringValue

Sets data for REG_MULTI_SZ value

SetStringValue

Sets data for REG_SZ value




Windows Server Cookbook
Windows Server Cookbook for Windows Server 2003 and Windows 2000
ISBN: 0596006330
EAN: 2147483647
Year: 2006
Pages: 380
Authors: Robbie Allen

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net