tieregistry.html
来自「perl教程」· HTML 代码 · 共 1,015 行 · 第 1/5 页
HTML
1,015 行
for more information.</p>
</dd>
</li>
<dt><strong><a name="item_reg_multi_sz">REG_MULTI_SZ</a></strong>
<dd>
<p>Several null-terminated strings concatenated together with an
extra trailing <code>'\0'</code> at the end of the list. Note that the list
can include empty strings so use the value's length to determine
the end of the list, not the first occurrence of <code>'\0\0'</code>.
It is best to set the <a href="#item_splitmultis"><code>SplitMultis()</code></a> option so <em>Win32::TieRegistry</em>
will split these values into an array of strings for you.</p>
</dd>
</li>
<dt><strong><a name="item_reg_dword">REG_DWORD</a></strong>
<dd>
<p>A long [4-byte] integer value. These values are expected either
packed into a 4-character string or as a hex string of &more than;
4 characters [but <em>not</em> as a numeric value, unfortunately, as there is
no sure way to tell a numeric value from a packed 4-byte string that
just happens to be a string containing a valid numeric value].</p>
</dd>
<dd>
<p>How such values are returned depends on the <a href="#item_dualbinvals"><code>DualBinVals()</code></a> and
<a href="#item_dwordstohex"><code>DWordsToHex()</code></a> options. See <a href="#item_getvalue"><code>GetValue()</code></a> for details.</p>
</dd>
</li>
</dl>
<p>In the underlying Registry calls, most places which take a
subkey name also allow you to pass in a subkey "path" -- a
string of several subkey names separated by the delimiter
character, backslash [<code>'\\'</code>]. For example, doing
<code>RegOpenKeyEx(HKEY_LOCAL_MACHINE,"SYSTEM\\DISK",...)</code> is much
like opening the <code>"SYSTEM"</code> subkey of <code>HKEY_LOCAL_MACHINE</code>,
then opening its <code>"DISK"</code> subkey, then closing the <code>"SYSTEM"</code>
subkey.</p>
<p>All of the <em>Win32::TieRegistry</em> features allow you to use your
own delimiter in place of the system's delimiter, [<code>'\\'</code>]. In
most of our examples we will use a forward slash [<code>'/'</code>] as our
delimiter as it is easier to read and less error prone to use when
writing Perl code since you have to type two backslashes for each
backslash you want in a string. Note that this is true even when
using single quotes -- <code>'\\HostName\LMachine\'</code> is an invalid
string and must be written as <code>'\\\\HostName\\LMachine\\'</code>.</p>
<p>You can also connect to the registry of other computers on your
network. This will be discussed more later.</p>
<p>Although the Registry does not have a single root key, the
<em>Win32::TieRegistry</em> module creates a virtual root key for you
which has all of the <em>HKEY_*</em> keys as subkeys.</p>
<p>
</p>
<h2><a name="tied_hashes_documentation">Tied Hashes Documentation</a></h2>
<p>Before you can use a tied hash, you must create one. One way to
do that is via:</p>
<pre>
<span class="keyword">use</span> <span class="variable">Win32::TieRegistry</span> <span class="operator">(</span> <span class="string">TiedHash</span> <span class="operator">=></span> <span class="string">'%RegHash'</span> <span class="operator">);</span>
</pre>
<p>which exports a <code>%RegHash</code> variable into your package and ties it
to the virtual root key of the Registry. An alternate method is:</p>
<pre>
<span class="keyword">my</span> <span class="variable">%RegHash</span><span class="operator">;</span>
<span class="keyword">use</span> <span class="variable">Win32::TieRegistry</span> <span class="operator">(</span> <span class="string">TiedHash</span> <span class="operator">=></span> <span class="operator">\</span><span class="variable">%RegHash</span> <span class="operator">);</span>
</pre>
<p>There are also several ways you can tie a hash variable to any
other key of the Registry, which are discussed later.</p>
<p>Note that you will most likely use <code>$Registry</code> instead of using
a tied hash. <code>$Registry</code> is a reference to a hash that has
been tied to the virtual root of your computer's Registry [as if,
<code>$Registry= \%RegHash</code>]. So you would use <code>$Registry->{Key}</code>
rather than <code>$RegHash{Key}</code> and use <code>keys %{$Registry}</code> rather
than <code>keys %RegHash</code>, for example.</p>
<p>For each hash which has been tied to a Registry key, the Perl
<a href="../../lib/Pod/perlfunc.html#item_keys"><code>keys</code></a> function will return a list containing the name of each
of the key's subkeys with a delimiter character appended to it and
containing the name of each of the key's values with a delimiter
prepended to it. For example:</p>
<pre>
<span class="keyword">keys</span><span class="operator">(</span> <span class="variable">%</span><span class="operator">{</span> <span class="variable">$Registry</span><span class="operator">-></span><span class="operator">{</span><span class="string">"HKEY_CLASSES_ROOT\\batfile\\"</span><span class="operator">}</span> <span class="operator">}</span> <span class="operator">)</span>
</pre>
<p>might yield the following list value:</p>
<pre>
( "DefaultIcon\\", # The subkey named "DefaultIcon"
"shell\\", # The subkey named "shell"
"shellex\\", # The subkey named "shellex"
"\\", # The default value [named ""]
"\\EditFlags" ) # The value named "EditFlags"</pre>
<p>For the virtual root key, short-hand subkey names are used as
shown below. You can use the short-hand name, the regular
<em>HKEY_*</em> name, or any numeric value to access these keys, but
the short-hand names are all that will be returned by the <a href="../../lib/Pod/perlfunc.html#item_keys"><code>keys</code></a>
function.</p>
<dl>
<dt><strong><a name="item__22classes_22_for_hkey_classes_root">"Classes" for HKEY_CLASSES_ROOT</a></strong>
<dd>
<p>Contains mappings between file name extensions and the uses
for such files along with configuration information for COM
[MicroSoft's Common Object Model] objects. Usually a link to
the <code>"SOFTWARE\\Classes"</code> subkey of the <code>HKEY_LOCAL_MACHINE</code>
key.</p>
</dd>
</li>
<dt><strong><a name="item__22cuser_22_for_hkey_current_user">"CUser" for HKEY_CURRENT_USER</a></strong>
<dd>
<p>Contains information specific to the currently logged-in user.
Mostly software configuration information. Usually a link to
a subkey of the <code>HKEY_USERS</code> key.</p>
</dd>
</li>
<dt><strong><a name="item__22lmachine_22_for_hkey_local_machine">"LMachine" for HKEY_LOCAL_MACHINE</a></strong>
<dd>
<p>Contains all manner of information about the computer.</p>
</dd>
</li>
<dt><strong><a name="item__22users_22_for_hkey_users">"Users" for HKEY_USERS</a></strong>
<dd>
<p>Contains one subkey, <code>".DEFAULT"</code>, which gets copied to a new
subkey whenever a new user is added. Also contains a subkey for
each user of the system, though only those for active users
[usually only one] are loaded at any given time.</p>
</dd>
</li>
<dt><strong><a name="item__22perfdata_22_for_hkey_performance_data">"PerfData" for HKEY_PERFORMANCE_DATA</a></strong>
<dd>
<p>Used to access data about system performance. Access via this key
is "special" and all but the most carefully constructed calls will
fail, usually with <code>ERROR_INSUFFICIENT_BUFFER</code>. For example, you
can't enumerate key names without also enumerating values which
require huge buffers but the exact buffer size required cannot be
determined beforehand because <code>RegQueryInfoKey()</code> &always; fails
with <code>ERROR_INSUFFICIENT_BUFFER</code> for <code>HKEY_PERFORMANCE_DATA</code> no
matter how it is called. So it is currently not very useful to
tie a hash to this key. You can use it to create an object to use
for making carefully constructed calls to the underlying Reg*()
routines.</p>
</dd>
</li>
<dt><strong><a name="item__22cconfig_22_for_hkey_current_config">"CConfig" for HKEY_CURRENT_CONFIG</a></strong>
<dd>
<p>Contains minimal information about the computer's current
configuration that is required very early in the boot process.
For example, setting for the display adapter such as screen
resolution and refresh rate are found in here.</p>
</dd>
</li>
<dt><strong><a name="item__22dyndata_22_for_hkey_dyn_data">"DynData" for HKEY_DYN_DATA</a></strong>
<dd>
<p>Dynamic data. We have found no documentation for this key.</p>
</dd>
</li>
</dl>
<p>A tied hash is much like a regular hash variable in Perl -- you give
it a key string inside braces, [<code>{</code> and <code>}</code>], and it gives you
back a value [or lets you set a value]. For <em>Win32::TieRegistry</em>
hashes, there are two types of values that will be returned.</p>
<dl>
<dt><strong><a name="item_subkeys">SubKeys</a></strong>
<dd>
<p>If you give it a string which represents a subkey, then it will
give you back a reference to a hash which has been tied to that
subkey. It can't return the hash itself, so it returns a
reference to it. It also blesses that reference so that it is
also an object so you can use it to call method functions.</p>
</dd>
</li>
<dt><strong><a name="item_values">Values</a></strong>
<dd>
<p>If you give it a string which is a value name, then it will give
you back a string which is the data for that value. Alternately,
you can request that it give you both the data value string and
the data value type [we discuss how to request this later]. In
this case, it would return a reference to an array where the value
data string is element <code>[0]</code> and the value data type is element
<code>[1]</code>.</p>
</dd>
</li>
</dl>
<p>The key string which you use in the tied hash must be interpreted
to determine whether it is a value name or a key name or a path
that combines several of these or even other things. There are
two simple rules that make this interpretation easy and
unambiguous:</p>
<pre>
Put a delimiter after each key name.
Put a delimiter in front of each value name.</pre>
<p>Exactly how the key string will be intepreted is governed by the
following cases, in the order listed. These cases are designed
to "do what you mean". Most of the time you won't have to think
about them, especially if you follow the two simple rules above.
After the list of cases we give several examples which should be
clear enough so feel free to skip to them unless you are worried
about the details.</p>
<dl>
<dt><strong><a name="item_remote_machines">Remote machines</a></strong>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?