The Windows Registry

The Windows registry is a unified database that stores hardware and software configuration information for a local computer. System and application data also is stored in the registry. The registry's role is similar to that stored in *.INI files in Windows 3.1. You can still use *.INI files in Windows 95; however, they primarily provide legacy support. The advantages of using the registry include the ability to assign multiple values to a key and attaching different types of data to the keys. Using network registry tools, the registry also can be accessed over a network for diagnostics and administration.

Registry Editor

In Windows 95 and Windows NT, the registry can be viewed or modified with the Registry Editor (REGEDIT.EXE), which is located in the Windows folder.

click to view at full size.

Figure 1.11 The Windows Registry Editor

Be careful when changing values using the Registry Editor, because it does not recognize errors in syntax or other semantics, and you are not warned if you have made an incorrect entry. If an incorrect entry is made, the operating system may be rendered unusable. In most cases, you do not have to modify the registry directly. Modifications to the system are best performed by using the appropriate user interface, such as the Device Manager or other parts of Control Panel.

Structure of the Registry

The registry is a tree-structured, hierarchical database. It is stored in two files that can vary with the configuration of the system, but will be split into a file containing settings specific to the user (typically USER.DAT). Each entry node in the registry tree is called a key . The registry is similar to a file system, in that each key can contain both subkeys (analogous to directories) and data entries (analogous to files). A key can have any number of data entries, and the data can be in any form. Each data entry is called a value .

Each key can contain the following items:


Key Component Required Description
Name Yes String used to gain access to the key. This key must be unique relative to other keys at the same hierarchical level.
Class No Object class name. Intended for use in associating class method code with class instances stored in the registry. Not normally used by applications.
Security Descriptor No Keys use standard Windows NT security descriptors and can express auditing control and full access control.
Last write time No A time stamp indicating the last time the key was modified. Any change to a value is considered a modification of the value's parent key.
Value(s) No Zero or many pieces of information to be stored with the key. Contains a name to identify the value, a type to define the type of data stored in the value, and the data to specify the user data of arbitrary length and format.

HKEY_CLASSES_ROOT

The HKEY_CLASSES_ROOT key contains the same type of data as the REG.DAT file did in Windows 3.1 ”information about OLE and file association mappings. This mapping allows Windows to run or print from a program when a specific data file is selected.

HKEY_LOCAL_MACHINE

The local machine contains specifications for the workstation, drivers, and other system settings. This is machine-specific information about the type of hardware that has been installed, how ports are mapped out, how software is configured, and other information. This information is specific to the machine, not the user.

HKEY_CURRENT_CONFIG

This key contains information about the current configuration of the hardware attached to the workstation. This key is used mainly when multiple configurations are available to the workstation, such as when a portable computer is docked to or undocked from the workstation. The information in the key is copied from the configuration information contained in the HKEY_LOCAL_MACHINE key.

HKEY_USERS

The users key contains information about all the users of the current workstation. This is where information for each user is stored. In addition, there is a generic user setting, which can serve as a template for new user's own keys. The generic settings include various defaults for programs, event schemes, desktop configurations, and so on.

HKEY_CURRENT_USER

This key contains user-specific settings for the system and programs. This is created at run time (when the user logs on) from information that is loaded from that user's entry in the HKEY_USERS registry section into this registry key. This is information about how the user wants to configure their workstation environment. For example, if the user specifies that a sound event (such as CHORD.WAV) should occur every time the system starts, then it is listed under this key in the registry. Other information can include the user's preferred color schemes, labels, desktop state, and so on.

HKEY_DYN_DATA

This key contains dynamic status information for various devices. The information under this key is regenerated each time the system starts. This key is used as part of the performance measuring information and also for Plug and Play configuration. This information can change as new devices are added to or removed from the system. The information for each device includes the associated hardware key, any problems, and the current status of the device. This key also contains information on system monitoring being performed with the System Monitor tool. HKEY_DYN_DATA is not a part of either registry file and is always created dynamically.

Modifying the Windows Registry

You can make your applications easier to use by saving information about user activity or preferences each time a user runs your application. This information can then be used in subsequent sessions. For example, you can save the name of the last database the user opened, and then use that name as the default database the next time your user opens a database.

To save application settings, you can use the Visual Basic statements SaveSetting and GetSetting or the Windows API routines.

The following syntax is used for SaveSetting and GetSetting in Visual Basic:

  • SaveSetting
  • ( appname , section, key, setting)
  • GetSetting
  • (appname, section, key,[default])

Example

The following example uses the SaveSetting statement to make an entry in the Windows registry for an application specified as "appname", and then uses the GetSetting function to retrieve the setting. Because the default argument is specified, a value is guaranteed to be returned.

 'Place some settings in the registry. SaveSetting "MyApp","Startup", "Top", 75 SaveSetting "MyApp","Startup", "Left", 50 

'Use the settings in the registry to display the current form. Me.Left = GetSetting(appname := "MyApp", _ section := "Startup", key := "Left", default := "0") Me.Top = GetSetting(appname := "MyApp", _ section := "Startup", key := "Top", default := "0")

Lesson Summary

A working knowledge of the Windows operating system begins with an understanding of the system architecture. The Windows operating system uses user mode and kernel mode of the Intel protection model to maintain operating system efficiency and integrity:

Windows 95 and Windows NT are both multitasking environments. In a multitasking system, multiple processes do not actually run at the same time. Instead, the processor can switch between multiple processes. In Window 95 and NT, each process has its own address space that enables it to address up to 4 GB of memory.

The Win32 application programming interface (Win32 API) allows applications to capitalize on the power of the Windows family of operating systems. The Win32 functions, messages, and structures form a consistent and uniform API for Windows 95 and Windows NT. Using the Win32 API, applications can be developed to run successfully on all platforms while retaining their ability to take advantage of unique features and capabilities of any given platform.

The Windows registry is a unified database that stores hardware and software configuration information for a local computer. The advantages of using the registry include the ability to assign multiple values to a key and attaching different types of data to the keys. Using network registry tools, the registry can also be accessed over a network for diagnostics and administration.



Microsoft Windows Architecture Training
Microsoft Windows Architecture for Developers Training Kit
ISBN: B00007FY9D
EAN: N/A
Year: 1998
Pages: 324

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