⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ch26.htm

📁 prrl 5 programs codes in the book
💻 HTM
📖 第 1 页 / 共 3 页
字号:
<HTML>

<HEAD>

<TITLE>Appendix D -- Using the Registry</TITLE>



<META>

</HEAD>

<BODY TEXT="#000000" BGCOLOR="#FFFFFF" LINK="#0000EE" VLINK="#551A8B" ALINK="#CE2910">

<H1><FONT SIZE=6 COLOR=#FF0000>Appendix&nbsp;D</FONT></H1>

<H1><FONT SIZE=6 COLOR=#FF0000>Using the Registry</FONT></H1>

<HR>

<P>

<CENTER><B><FONT SIZE=5>CONTENTS</FONT></B></CENTER>

<UL>

<LI><A HREF="#RegistryFiles">

Registry Files</A>

<UL>

<LI><A HREF="#HowtoBackUptheRegistry">

How to Back Up the Registry</A>

<LI><A HREF="#HowtoRestoretheRegistry">

How to Restore the Registry</A>

</UL>

<LI><A HREF="#UsingtheRegistry">

Using the Registry</A>

<UL>

<LI><A HREF="#OpeninganExistingKey">

Opening an Existing Key</A>

<LI><A HREF="#CreatingaNewKey">

Creating a New Key</A>

<LI><A HREF="#FindingaKeysValue">

Finding a Key's Value</A>

<LI><A HREF="#SettingaKeysNameValuePairs">

Setting a Key's Name-Value Pairs</A>

<LI><A HREF="#GettingaListofSubkeys">

Getting a List of Subkeys</A>

<LI><A HREF="#GettingaListofNameValuePairs">

Getting a List of Name-Value Pairs</A>

</UL>

<LI><A HREF="#SomeCommonUsesfortheRegistry">

Some Common Uses for the Registry</A>

<UL>

<LI><A HREF="#CreatingaFileAssociation">

Creating a File Association</A>

<LI><A HREF="#SettingtheIconforaFileExtension">

Setting the Icon for a File Extension</A>

<LI><A HREF="#EnablingthenewContextMenuOption">

Enabling the 'new' Context Menu Option</A>

</UL>

<LI><A HREF="#Summary">

Summary</A>

</UL>



<HR>

<P>

In Windows 3.1, INI or initialization files were used to hold

information used to configure application programs. For example,

an INI file might have a list of the most recently used files

or hold the status of an option to save modified files. However,

INI files had several weaknesses:

<UL>

<LI><B>UNCertain location</B>-INI files could be found in either

the <TT>\windows</TT> directory or

the application's directory.

<LI><B>Size limitations</B>-INI files were limited to 64K bytes.

<LI><B>Easy to modify</B>-INI files were simple text files. End-users

could modify them and create technical support problems.

<LI><B>Hard to back up</B>-SiNCe INI files can be in any directory,

it was nearly impossible to back up and restore application configurations.

</UL>

<P>

These problems, and others, prompted Microsoft to design the Registry.

The <I>Registry</I> is a database that contains information about

your operating system, its applications and file associations.

An exhaustive list of the different types of information is too

long to reproduce here. Suffice to say that the Registry holds

both hardware and software information.<BR>

<p>

<CENTER>

<TABLE BORDERCOLOR=#000000 BORDER=1 WIDTH=80%>

<TR><TD><B>Caution</B></TD></TR>

<TR><TD>

<BLOCKQUOTE>

<TT><B><FONT FACE="Courier">Changing the Registry is dangerous!</FONT></B></TT> Make sure that your Registry is backed up and you can afford to totally wreck your test machine. I'm serious; don't mess with the Registry unless you can afford to take the 
time to back up your system.

</BLOCKQUOTE>



</TD></TR>

</TABLE>

</CENTER>

<P>

<P>

There are several advantages to using the Registry:

<UL>

<LI><B>Known location</B>-Any program can look into the Registry

to see if it has already been loaded. Or it can see if other programs

have been loaded.

<LI><B>Hard to modify</B>-The normal computer user will not know

about the Registry so he or she won't try to change it which means

that configuration errors are less likely.

<LI><B>Easy to back up</B>-Keeping all of the configuration information

in two files makes it very easy to back up the Registry. In fact,

Windows keeps several backups on its own. The Registry files are

discussed in the &quot;Registry Files&quot; section a bit later

in this chapter.

</UL>

<P>

Information in the Registry is stored in a <I>key-value format</I>.

This means that every value stored in the Registry has an associated

key. Similar to the lock on your front door. You can't unlock

the door without the correct key. Likewise, you can't retrieve

the stored value without the correct key. Each key can have both

subkeys andone or more sets of name-value pairs. In fact, you

might think of eachkey as an associative array. For example, there

is a key called <TT>HKEY_USERS\Default\Software\Microsoft\User

information</TT> that is interesting. This key has several

name-value pairs. Here is a small sampling of the name-value pairs

from the Registry on my system:<BR>



<p>

<CENTER>

<TABLE BORDERCOLOR=#000000 BORDER=1 WIDTH=80%>

<TR><TD WIDTH=163><I>Name</I></TD><TD WIDTH=222><I>Value</I></TD>

</TR>

<TR><TD WIDTH=163>Operating System</TD><TD WIDTH=222>Microsoft Windows 95

</TD></TR>

<TR><TD WIDTH=163>Processor</TD><TD WIDTH=222>Pentium</TD></TR>

<TR><TD WIDTH=163>Default Company</TD><TD WIDTH=222>Eclectic Consulting

</TD></TR>

<TR><TD WIDTH=163>Default First Name</TD><TD WIDTH=222>David</TD>

</TR>

</TABLE>

</CENTER>

<P>

<P>

In addition to named values, there is an unnamed default value

that is referred to using an empty string as the name.<BR>

<p>

<CENTER>

<TABLE BORDERCOLOR=#000000 BORDER=1 WIDTH=80%>

<TR><TD><B>Note</B></TD></TR>

<TR><TD>

<BLOCKQUOTE>

The coNCept of a default name-value will become clear if you peek ahead to Figure 22.6 where you'll see a Registry key with several name-value keys defined.</BLOCKQUOTE>



</TD></TR>

</TABLE>

</CENTER>

<P>

<P>

As you may guess from looking at the key just mentioned, all of

the information in the Registry is stored in a hierarchical or

tree format-similar to a directory structure. Each key can have

subkeys. There are three root or base keys:

<UL>

<LI><TT>HKEY_DYN_DATA</TT>-The subkeys

under this Windows 95 specific key holds system information that

will last only as long as the computer is not shutdown or rebooted.

In other words, these keys are never written to the hard disk,

they exist only in RAM. There are two subkeys: <TT>PerfStats</TT>,

which holds network performaNCe statistics and <TT>Config

Manager</TT>, which keeps a list of all devices on the

computer.

<LI><TT>HKEY_LOCAL_MACHINE</TT>-The

subkeys under this key hold information about the local computer

and its configuration. It is one of the most used root keys.

<LI><TT>HKEY_USERS</TT>-The subkeys

under <TT>HKEY_USERS</TT> hold information

about all of the users who have logged into your system. The .Default

subtree stores information about the default users. Each individual

user will have a subtree of their own.

</UL>

<P>

Some of the Registry information is accessed so often that Microsoft

has provided three shortcut keys:

<UL>

<LI><TT>HKEY_CLASSES_ROOT</TT>-This

key is identical to <TT>HKEY_LOCAL_MACHINE\SOFTWARE\

<BR>

Classes</TT>. Changing Registry information in either location

changes both locations. Document types, document associations,

and OLE information are stored under this key.

<LI><TT>HKEY_CURRENT_CONFIG</TT>-This

key is identical to <TT>HKEY_LOCAL_MACHINE\Config</TT>.

The hardware and system configuration information that is most

likely to change is stored under this key.

<LI><TT>HKEY_CURRENT_USER</TT>-This

key is a shortcut to the selected user profile in <TT>HKEY_USERS</TT>.

It holds information about the configuration and prefereNCes for

the currently signed-on user.

</UL>

<P>

<p>

<CENTER>

<TABLE BORDERCOLOR=#000000 BORDER=1 WIDTH=80%>

<TR><TD><B>Caution</B></TD></TR>

<TR><TD>

<BLOCKQUOTE>

Remember, <TT><B><FONT FACE="Courier">changing the Registry is dangerous!</FONT></B></TT> Make sure that your Registry is backed up before making changes.

</BLOCKQUOTE>



</TD></TR>

</TABLE>

</CENTER>

<P>

<H2><A NAME="RegistryFiles"><FONT SIZE=5 COLOR=#FF0000>

Registry Files</FONT></A></H2>

<P>

There are two files associated with the Registry. The <TT>user.dat</TT>

file holds user-specific data, and the <TT>system.dat</TT>

file holds everything else. They are located in the <TT>\windows</TT>

directory and have their hidden, system, and read-only attributes

turned on. This means that if you run the <TT>dir</TT>

command while connected to those directories, you will not see

these files. When the system is booted, both files are read and

a single Registry is created in memory.

<P>

The <TT>user.da0</TT> and <TT>system.da0</TT>

files in the <TT>\windows</TT> directory

are copies of the Registry from a successful boot of the computer

system. If the Registry gets corrupted, Windows will try to fix

the problem by using these earlier versions.

<P>

You will also find a <TT>system.1st</TT>

file in the root directory of your boot drive (usually <TT>C:</TT>).

The file was created when you first installed Windows. If Windows

can't recover from a Registry failure using the DA0 files, you

can try using <TT>system.1st</TT>

file.

<H3><A NAME="HowtoBackUptheRegistry">

How to Back Up the Registry</A></H3>

<P>

You can manually back up the Registry by exporting the information

using the Windows regedit utility. This utility lets you export

all of the Registry information to a text file. Follow these steps

to perform the export:

<OL>

<LI>From the Windows Start Button, select the <U>R</U>un... option.

<LI>Type <B>regedit</B> into the Run dialog box. Figure D.1 shows

the dialog box.<BR>

<BR>

<A HREF="fd-1.gif" tppabs="http://cheminf.nankai.edu.cn/~eb~/Perl%205%20By%20Example/fd-1.gif"><B>Figure D.1 : </B><I>Using the Run dialog box to start the regedit

utility</I>.</A>

<LI>Click the OK button. The Registry Editor program will start,

as shown in Figure D.2.<BR>

<BR>

<A HREF="fd-2.gif" tppabs="http://cheminf.nankai.edu.cn/~eb~/Perl%205%20By%20Example/fd-2.gif"><B>Figure D.2 : </B><I>The Registry Editor is used to view and

modify registry information</I>.</A>

<LI>Choose <U>R</U>egistry, <U>E</U>xport Registry File. The dialog

box in Figure D.3 is shown.

<LI>Type in a filename (for example, <TT>c:\backup.reg</TT>),

and then click the <U>S</U>ave button.<BR>

<BR>

<A HREF="fd-3.gif" tppabs="http://cheminf.nankai.edu.cn/~eb~/Perl%205%20By%20Example/fd-3.gif"><B>Figure D.3 : </B><I>The Export Registry File dialog box</I>.</A>

</OL>

<P>

This procedure creates a text-based backup of the Registry. You

should copy this file onto a diskette or other data storage medium.

You will probably need to compress the resulting backup file siNCe

mine was over 1.8 million bytes in length-too long to place on

a diskette.

<P>

You can also boot your system into DOS mode and copy the <TT>\windows\user.dat</TT>

and <TT>\windows\system.dat</TT> files

either onto a diskette or into a directory other than <TT>\windows</TT>.

<H3><A NAME="HowtoRestoretheRegistry">

How to Restore the Registry</A></H3>

<P>

Now that you know how to back up the Registry by using the export

feature of the Registry Editor, let's look at restoring the Registry

using the import feature. Use this procedure to import the text-based

Registry file:

<OL>

<LI>From the Windows Start Button, select the <U>R</U>un... option.

<LI>Type <B>regedit</B> into the Run dialog box and click the

OK button.

<LI>Choose <U>R</U>egistry, <U>I</U>mport Registry File. The dialog

box in Figure D.4 is shown.

<LI>Enter the name of the text-based registry file (for example,

<TT>c:\backup.reg</TT>) and click

the <U>O</U>pen button.

<LI>Reboot your system.<BR>

<BR>

<A HREF="fd-4.gif" tppabs="http://cheminf.nankai.edu.cn/~eb~/Perl%205%20By%20Example/fd-4.gif"><B>Figure D.4 : </B><I>The Import Registry File dialog box lets

you select a file to restore from</I>.</A>

</OL>

<P>

If your system is still not working, and you have copied the two

Registry files and were created in the previous section, &quot;How

to Back Up the Registry,&quot; then you can try rebooting to DOS

and copy the two backup files directly into the <TT>\windows</TT>

directory. After copying the files, reboot your system.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -