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

📄 ch9.htm

📁 《Perl 5 Unreleased》
💻 HTM
📖 第 1 页 / 共 5 页
字号:
<BLOCKQUOTE>

<TT><FONT FACE="Courier">NTRegLoadKey $hkey, $subkey, FILE</FONT></TT>

</BLOCKQUOTE>

<BLOCKQUOTE>

The <TT><FONT FACE="Courier">NTRegLoadKey</FONT></TT> function

creates a <TT><FONT FACE="Courier">$subkey</FONT></TT> under <TT><FONT FACE="Courier">$hkey_USER</FONT></TT>

or <TT><FONT FACE="Courier">$hkey_LOCAL_MAchINE</FONT></TT> and

stores registration information from a specified <TT><FONT FACE="Courier">FILE</FONT></TT>

into that <TT><FONT FACE="Courier">$subkey</FONT></TT>.

</BLOCKQUOTE>

<H5>NTRegOpenKey</H5>

<BLOCKQUOTE>

The <TT><FONT FACE="Courier">NTRegOpenKey</FONT></TT> function

opens the <TT><FONT FACE="Courier">$subkey</FONT></TT> under the

key <TT><FONT FACE="Courier">$hkey</FONT></TT> and returns the

handle of the opened key in <TT><FONT FACE="Courier">$result</FONT></TT>.

This is an old function that will be replaced by the <TT><FONT FACE="Courier">NTRegOpenKeyEx</FONT></TT>

function. The syntax for this function is

</BLOCKQUOTE>

<BLOCKQUOTE>

<TT><FONT FACE="Courier">NTRegOpenKey $hkey, $subkey, $result</FONT></TT>

</BLOCKQUOTE>

<H5>NTRegOpenKeyEx</H5>

<BLOCKQUOTE>

The <TT><FONT FACE="Courier">NTRegOpenKeyEx</FONT></TT> key function

is a later version of <TT><FONT FACE="Courier">NTRegOpenKey</FONT></TT>.

Its syntax is

</BLOCKQUOTE>

<BLOCKQUOTE>

<TT><FONT FACE="Courier">NTRegOpenKeyEx $hkey, $subkey, NULL,

$sam, $result</FONT></TT>

</BLOCKQUOTE>

<BLOCKQUOTE>

The <TT><FONT FACE="Courier">NTRegOpenKeyEx</FONT></TT> function

opens <TT><FONT FACE="Courier">$subkey</FONT></TT> under <TT><FONT FACE="Courier">$hkey</FONT></TT>

with the system access mode <TT><FONT FACE="Courier">$sam</FONT></TT>,

returning the handle of the opened key in <TT><FONT FACE="Courier">$result</FONT></TT>.

Unlike the <TT><FONT FACE="Courier">NTRegCreateKeyEx</FONT></TT>

function, the <TT><FONT FACE="Courier">NTRegOpenKeyEx</FONT></TT>

function will not create the specified key if the key does not

exist in the Registry.

</BLOCKQUOTE>

<H5>NTRegQueryInfoKey</H5>

<BLOCKQUOTE>

The <TT><FONT FACE="Courier">NTRegQueryInfoKey</FONT></TT> function

retrieves information about a key. Its syntax is

</BLOCKQUOTE>

<BLOCKQUOTE>

<TT><FONT FACE="Courier">NTRegQueryInfoKey $hkey,<BR>

&nbsp;&nbsp;&nbsp;&nbsp;$class, NULL, $nsubkeys, $maxsubkey, $maxclass,

<BR>

&nbsp;&nbsp;&nbsp;&nbsp;$nvalues, $maxvaluename, $maxvaluedata,

$security_descriptor,<BR>

&nbsp;&nbsp;&nbsp;&nbsp;$lastwritetime</FONT></TT>

</BLOCKQUOTE>

<BLOCKQUOTE>

Here are the output parameters for <TT><FONT FACE="Courier">$hkey</FONT></TT>:

<P>

</BLOCKQUOTE>

<CENTER>

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

<TR VALIGN=TOP><TD WIDTH=215><TT><FONT FACE="Courier">$CLASS</FONT></TT>

</TD><TD WIDTH=205>The key class</TD></TR>

<TR VALIGN=TOP><TD WIDTH=215><TT><FONT FACE="Courier">$NSUBKEYS</FONT></TT>

</TD><TD WIDTH=205>The number of subkeys</TD></TR>

<TR VALIGN=TOP><TD WIDTH=215><TT><FONT FACE="Courier">$MAXSUBKEY</FONT></TT>

</TD><TD WIDTH=205>The longest subkey name</TD></TR>

<TR VALIGN=TOP><TD WIDTH=215><TT><FONT FACE="Courier">$MAXCLASS</FONT></TT>

</TD><TD WIDTH=205>The longest class name</TD></TR>

<TR VALIGN=TOP><TD WIDTH=215><TT><FONT FACE="Courier">$NVALUES</FONT></TT>

</TD><TD WIDTH=205>The number of values</TD></TR>

<TR VALIGN=TOP><TD WIDTH=215><TT><FONT FACE="Courier">$MAXVALUENAME</FONT></TT>

</TD><TD WIDTH=205>The longest value name</TD></TR>

<TR VALIGN=TOP><TD WIDTH=215><TT><FONT FACE="Courier">$MAXVALUEDATA</FONT></TT>

</TD><TD WIDTH=205>The longest value data block</TD></TR>

<TR VALIGN=TOP><TD WIDTH=215><TT><FONT FACE="Courier">$SECURITY_DESCRIPTOR</FONT></TT>

</TD><TD WIDTH=205>See Windows 32 API</TD></TR>

<TR VALIGN=TOP><TD WIDTH=215><TT><FONT FACE="Courier">$LASTWRITETIME</FONT></TT>

</TD><TD WIDTH=205>The time when modified last</TD></TR>

</TABLE></CENTER>

<P>

<H5>NTRegQueryValue</H5>

<BLOCKQUOTE>

The <TT><FONT FACE="Courier">NTRegQueryValue</FONT></TT> is an

obsolete version of <TT><FONT FACE="Courier">NTRegQueryValueEx</FONT></TT>

and is provided only for compatibility with older scripts. The

syntax is

</BLOCKQUOTE>

<BLOCKQUOTE>

<TT><FONT FACE="Courier">The NTRegQueryValue $hkey, $subkey, $data</FONT></TT>

</BLOCKQUOTE>

<H5>NTRegQueryValueEx</H5>

<BLOCKQUOTE>

The <TT><FONT FACE="Courier">NTRegQueryValueEx</FONT></TT> function

is used to get the <TT><FONT FACE="Courier">$type</FONT></TT>

and <TT><FONT FACE="Courier">$data</FONT></TT> for a specified

<TT><FONT FACE="Courier">$valueName</FONT></TT> associated with

the open Registry key <TT><FONT FACE="Courier">$hkey</FONT></TT>.

The syntax for this command is

</BLOCKQUOTE>

<BLOCKQUOTE>

<TT><FONT FACE="Courier">NTRegQueryValueEx $hkey, $valueName,

NULL, $type, $data</FONT></TT>

</BLOCKQUOTE>

<H5>NTRegReplaceKey</H5>

<BLOCKQUOTE>

The <TT><FONT FACE="Courier">NTRegReplaceKey</FONT></TT> function

replaces the file backing a key and all its subkeys with another

file. You need to restart the system for the change to take effect.

The syntax for this call is

</BLOCKQUOTE>

<BLOCKQUOTE>

<TT><FONT FACE="Courier">NTRegReplaceKey $hkey, $subkey, $newFile,

$backupFile</FONT></TT>

</BLOCKQUOTE>

<BLOCKQUOTE>

The file specified by the <TT><FONT FACE="Courier">$newFile</FONT></TT>

parameter stays open until the system is restarted. This function

is a privileged call in NT and the calling process must be of

the <TT><FONT FACE="Courier">SE_RESTORE_NAME</FONT></TT> privilege.

</BLOCKQUOTE>

<H5>NTRegRestoreKey</H5>

<BLOCKQUOTE>

The syntax for the <TT><FONT FACE="Courier">NTRegRestoreKey</FONT></TT>

function is

</BLOCKQUOTE>

<BLOCKQUOTE>

<TT><FONT FACE="Courier">NTRegRestoreKey $hkey, $filename, $flags</FONT></TT>

</BLOCKQUOTE>

<BLOCKQUOTE>

The <TT><FONT FACE="Courier">NTRegRestoreKey</FONT></TT> function

reads the Registry information in a specified file and copies

it over the specified key. This Registry information may be in

the form of a key and multiple levels of subkeys.

</BLOCKQUOTE>

<H5>NTRegSaveKey</H5>

<BLOCKQUOTE>

The <TT><FONT FACE="Courier">NTRegSaveKey</FONT></TT> function

saves the specified key <TT><FONT FACE="Courier">$hkey</FONT></TT>

and all of its subkeys and values to a new file called <TT><FONT FACE="Courier">$filename</FONT></TT>,

with security settings specified by <TT><FONT FACE="Courier">$securityAttributes</FONT></TT>.

The syntax for this function is

</BLOCKQUOTE>

<BLOCKQUOTE>

<TT><FONT FACE="Courier">NTRegSaveKey $hkey, $filename, $securityAttributes</FONT></TT>

</BLOCKQUOTE>

<BLOCKQUOTE>

The calling script must be with the <TT><FONT FACE="Courier">SetBackupPrivilege</FONT></TT>

security privilege. The <TT><FONT FACE="Courier">NTRegSaveKey</FONT></TT>

function will save only the nonvolatile keys. It will not save

volatile keys. A key is made volatile or nonvolatile when created

with the underlying NT system call to <TT><FONT FACE="Courier">RegCreateKeyEx</FONT></TT>.

In most cases, you would be using the security field in a compiled

C program for security reasons and not in an interpreted, hence

modifiable, Perl program.

</BLOCKQUOTE>

<H5>NTRegSetKeySecurity</H5>

<BLOCKQUOTE>

The <TT><FONT FACE="Courier">NTRegSetKeySecurity</FONT></TT> function

sets the security of an open Registry key. The syntax for this

call is

</BLOCKQUOTE>

<BLOCKQUOTE>

<TT><FONT FACE="Courier">NTRegSetKeySecurity $hkey, $securityInformation,

$descriptor</FONT></TT>

</BLOCKQUOTE>

<BLOCKQUOTE>

Security issues in NT are well beyond the scope of this text.

Please refer to the Win32 API for more detailed information. One

thing to keep in mind is that the security information is not

changed until you open the key in <TT><FONT FACE="Courier">$hkey</FONT></TT>.

It's easier to close and reopen the key for the new security attributes

to work.

</BLOCKQUOTE>

<H5>NTRegSetValue</H5>

<BLOCKQUOTE>

The <TT><FONT FACE="Courier">NTRegSetValue</FONT></TT> function

associates a value with <TT><FONT FACE="Courier">$subkey</FONT></TT>

under the key <TT><FONT FACE="Courier">$hkey</FONT></TT>. This

value must be of type <TT><FONT FACE="Courier">REG_SZ</FONT></TT>

and cannot have a name. This function is an older version of <TT><FONT FACE="Courier">NTRegSetValueEx</FONT></TT>

and is only provided for backward compatibility. Its syntax is

</BLOCKQUOTE>

<BLOCKQUOTE>

<TT><FONT FACE="Courier">NTRegSetValue $hkey, $subkey, $type,

$data</FONT></TT>

</BLOCKQUOTE>

<H5>NTRegSetValueEx</H5>

<BLOCKQUOTE>

The <TT><FONT FACE="Courier">NTRegSetValueEx</FONT></TT> function

stores the value-data pair <TT><FONT FACE="Courier">{$valueName,$data}</FONT></TT>

in the named key <TT><FONT FACE="Courier">$hkey</FONT></TT> in

<TT><FONT FACE="Courier">$valueName</FONT></TT>. The syntax is

</BLOCKQUOTE>

<BLOCKQUOTE>

<TT><FONT FACE="Courier">NTRegSetValueEx $hkey, $valueName, NULL,

$type, $data</FONT></TT>

</BLOCKQUOTE>

<BLOCKQUOTE>

The length of the <TT><FONT FACE="Courier">$value</FONT></TT>

parameter must be limited to 2,048 bytes or less. Longer values

such as bitmaps, icons, data files, and so on can be stored in

files whose pathnames can be recorded in the Registry. The key

in the <TT><FONT FACE="Courier">$hkey</FONT></TT> parameter must

have been opened with <TT><FONT FACE="Courier">KEY_SET_VALUE</FONT></TT>

access in one of the two functions: <TT><FONT FACE="Courier">NTRegCreateKeyEx</FONT></TT>

or <TT><FONT FACE="Courier">NTRegOpenKeyEx</FONT></TT>. The <TT><FONT FACE="Courier">$type</FONT></TT>

variable can be set to <TT><FONT FACE="Courier">REG_SZ</FONT></TT>,

<TT><FONT FACE="Courier">REG_MULTI_SZ</FONT></TT>, or <TT><FONT FACE="Courier">REG_EXPAND_SZ</FONT></TT>.

</BLOCKQUOTE>

<H5>NTRegUnLoadKey</H5>

<BLOCKQUOTE>

The <TT><FONT FACE="Courier">NTRegUnLoadKey</FONT></TT> unloads

the key and its children specified by <TT><FONT FACE="Courier">$subkey</FONT></TT>

under <TT><FONT FACE="Courier">$hkey</FONT></TT> from the Registry

in memory but does not modify the underlying file. The syntax

is

</BLOCKQUOTE>

<BLOCKQUOTE>

<TT><FONT FACE="Courier">NTRegUnLoadKey $hkey, $subkey</FONT></TT>

</BLOCKQUOTE>

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

with Windows 95</FONT></A></H2>

<P>

The <TT><FONT FACE="Courier">command.com</FONT></TT> command interpreter

in Windows 95 is still 16-bit. Perl is destined to run in 32 bits

and is more suitable for NT. A number of Perl functions that would

work under NT and UNIX will break in the Windows 95 environment.

Some of these problems are fixed by using the 32-bit command interpreter

wrapper that's supplied with Win32 Perl in the <TT><FONT FACE="Courier">bin</FONT></TT>

subdirectory as <TT><FONT FACE="Courier">cmd32.exe</FONT></TT>.

You can also configure Perl to use another shell such as MKS Inc.'s

Korn shell for Windows 95.

<P>

To change the shell setting you must edit the Registry. Change

the following string in the Registry to the full path of your

shell:

<BLOCKQUOTE>

<TT><FONT FACE="Courier">HKEY_LOCAL_MAchINE\Software\Microsoft\ResourceKit\PERL5\WIN95SHELL</FONT></TT>

</BLOCKQUOTE>

<P>

Here are some notable problems in the Windows 95 environment:

<UL>

<LI><FONT COLOR=#000000>Unreliable exception handling through

signals and traps.</FONT>

<LI><FONT COLOR=#000000>Pipes do not work.</FONT>

<LI><FONT COLOR=#000000>Return codes from </FONT><TT><FONT FACE="Courier">fork()</FONT></TT>

may not be reliable.

<LI><FONT COLOR=#000000>There is no </FONT><TT><FONT FACE="Courier">stderr</FONT></TT>

redirection in <TT><FONT FACE="Courier">command.com</FONT></TT>.

For example, <TT><FONT FACE="Courier">exec &quot;doit 2&gt;output.txt&quot;</FONT></TT>

will not work.

</UL>

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

</H2>

<P>

This has been a very brief introduction to using Perl 5 on Windows

NT and Windows 95 machines. The process of porting Perl to these

platforms is not complete and is prone to some bugs. However,

general Perl scripts that do not deal with system calls will be

able to run on NT and UNIX machines without many problems.

<P>

<HR WIDTH="100%"></P>



<CENTER><P><A HREF="ch8.htm" tppabs="http://www.mcp.com/815097600/0-672/0-672-30891-6/ch8.htm"><IMG SRC="pc.gif" tppabs="http://www.mcp.com/815097600/0-672/0-672-30891-6/pc.gif" BORDER=0 HEIGHT=88 WIDTH=140></A><A HREF="#CONTENTS"><IMG SRC="cc.gif" tppabs="http://www.mcp.com/815097600/0-672/0-672-30891-6/cc.gif" BORDER=0 HEIGHT=88 WIDTH=140></A><A HREF="index.htm" tppabs="http://www.mcp.com/815097600/0-672/0-672-30891-6/index.htm"><IMG SRC="hb.gif" tppabs="http://www.mcp.com/815097600/0-672/0-672-30891-6/hb.gif" BORDER=0 HEIGHT=88 WIDTH=140></A><A HREF="ch10.htm" tppabs="http://www.mcp.com/815097600/0-672/0-672-30891-6/ch10.htm"><IMG 

SRC="nc.gif" tppabs="http://www.mcp.com/815097600/0-672/0-672-30891-6/nc.gif" BORDER=0 HEIGHT=88 WIDTH=140></A></P></CENTER>



<P>

<HR WIDTH="100%"></P>



</BODY>

</HTML>

⌨️ 快捷键说明

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