tieregistry.html
来自「perl教程」· HTML 代码 · 共 1,015 行 · 第 1/5 页
HTML
1,015 行
<dd>
<p>Since the "Windows" key should contain subkeys, that <a href="../../lib/Pod/perlfunc.html#item_delete"><code>delete</code></a>
statement should make no changes to the Registry, return <a href="../../lib/Pod/perlfunc.html#item_undef"><code>undef</code></a>,
and set <a href="../../lib/Pod/perlvar.html#item___e"><code>$^E</code></a> to "Access is denied".</p>
</dd>
</li>
<dt><strong><a name="item_not_deleting_again">Not deleting again</a></strong>
<dd>
<pre>
<span class="variable">$tips</span><span class="operator">=</span> <span class="variable">$Registry</span><span class="operator">-></span><span class="operator">{</span><span class="string">"CUser/Software/Microsoft/Windows/"</span> <span class="operator">.</span>
<span class="string">"CurrentVersion/Explorer/Tips/"</span><span class="operator">}</span><span class="operator">;</span>
<span class="keyword">delete</span> <span class="variable">$tips</span><span class="operator">;</span>
</pre>
</dd>
<dd>
<p>The Perl <a href="../../lib/Pod/perlfunc.html#item_delete"><code>delete</code></a> function requires that its argument be an
expression that ends in a hash element lookup [or hash slice],
which is not the case here. The <a href="../../lib/Pod/perlfunc.html#item_delete"><code>delete</code></a> function doesn't
know which hash $tips came from and so can't delete it.</p>
</dd>
</dl>
<p>
</p>
<h2><a name="objects_documentation">Objects Documentation</a></h2>
<p>The following member functions are defined for use on
<em>Win32::TieRegistry</em> objects:</p>
<dl>
<dt><strong><a name="item_new">new</a></strong>
<dd>
<p>The <a href="#item_new"><code>new</code></a> method creates a new <em>Win32::TieRegistry</em> object.
<a href="#item_new"><code>new</code></a> is mostly a synonym for <a href="#item_open"><code>Open()</code></a> so see <a href="#item_open"><code>Open()</code></a> below for
information on what arguments to pass in. Examples:</p>
</dd>
<dd>
<pre>
<span class="variable">$machKey</span><span class="operator">=</span> <span class="variable">new</span> <span class="variable">Win32::TieRegistry</span> <span class="string">"LMachine"</span>
<span class="keyword">or</span> <span class="keyword">die</span> <span class="string">"Can't access HKEY_LOCAL_MACHINE key: $^E\n"</span><span class="operator">;</span>
<span class="variable">$userKey</span><span class="operator">=</span> <span class="variable">Win32::TieRegistry</span><span class="operator">-></span><span class="variable">new</span><span class="operator">(</span><span class="string">"CUser"</span><span class="operator">)</span>
<span class="keyword">or</span> <span class="keyword">die</span> <span class="string">"Can't access HKEY_CURRENT_USER key: $^E\n"</span><span class="operator">;</span>
</pre>
</dd>
<dd>
<p>Note that calling <a href="#item_new"><code>new</code></a> via a reference to a tied hash returns
a simple object, not a reference to a tied hash.</p>
</dd>
</li>
<dt><strong><a name="item_open">Open</a></strong>
<dt><strong>$subKey= $key->Open( $sSubKey, $rhOptions )</strong>
<dd>
<p>The <a href="#item_open"><code>Open</code></a> method opens a Registry key and returns a new
<em>Win32::TieRegistry</em> object associated with that Registry key.
If <a href="#item_open"><code>Open</code></a> is called via a reference to a tied hash, then <a href="#item_open"><code>Open</code></a>
returns another reference to a tied hash. Otherwise <a href="#item_open"><code>Open</code></a>
returns a simple object and you should then use <a href="#item_tiedref"><code>TiedRef</code></a> to get
a reference to a tied hash.</p>
</dd>
<dd>
<p><code>$sSubKey</code> is a string specifying a subkey to be opened.
Alternately <code>$sSubKey</code> can be a reference to an array value
containing the list of increasingly deep subkeys specifying the
path to the subkey to be opened.</p>
</dd>
<dd>
<p><code>$rhOptions</code> is an optional reference to a hash containing extra
options. The <a href="#item_open"><code>Open</code></a> method supports two options, <code>"Delimiter"</code>
and <code>"Access"</code>, and <code>$rhOptions</code> should have only have zero or
more of these strings as keys. See the "Examples" section below
for more information.</p>
</dd>
<dd>
<p>The <code>"Delimiter"</code> option specifies what string [usually a single
character] will be used as the delimiter to be appended to subkey
names and prepended to value names. If this option is not specified,
the new key [<code>$subKey</code>] inherits the delimiter of the old key
[<code>$key</code>].</p>
</dd>
<dd>
<p>The <code>"Access"</code> option specifies what level of access to the
Registry key you wish to have once it has been opened. If this
option is not specified, the new key [<code>$subKey</code>] is opened with
the same access level used when the old key [<code>$key</code>] was opened.
The virtual root of the Registry pretends it was opened with
access <code>KEY_READ()|KEY_WRITE()</code> so this is the default access when
opening keys directory via <code>$Registry</code>. If you don't plan on
modifying a key, you should open it with <code>KEY_READ</code> access as
you may not have <code>KEY_WRITE</code> access to it or some of its subkeys.</p>
</dd>
<dd>
<p>If the <code>"Access"</code> option value is a string that starts with
<code>"KEY_"</code>, then it should match &one; of the predefined access
levels [probably <code>"KEY_READ"</code>, <code>"KEY_WRITE"</code>, or
<code>"KEY_ALL_ACCESS"</code>] exported by the <em>Win32API::Registry</em> module.
Otherwise, a numeric value is expected. For maximum flexibility,
include <code>use Win32::TieRegistry qw(:KEY_);</code>, for example, near
the top of your script so you can specify more complicated access
levels such as <code>KEY_READ()|KEY_WRITE()</code>.</p>
</dd>
<dd>
<p>If <code>$sSubKey</code> does not begin with the delimiter [or <code>$sSubKey</code>
is an array reference], then the path to the subkey to be opened
will be relative to the path of the original key [<code>$key</code>]. If
<code>$sSubKey</code> begins with a single delimiter, then the path to the
subkey to be opened will be relative to the virtual root of the
Registry on whichever machine the original key resides. If
<code>$sSubKey</code> begins with two consectutive delimiters, then those
must be followed by a machine name which causes the <a href="#item_connect"><code>Connect()</code></a>
method function to be called.</p>
</dd>
<dd>
<p>Examples:</p>
</dd>
<dd>
<pre>
<span class="variable">$machKey</span><span class="operator">=</span> <span class="variable">$Registry</span><span class="operator">-></span><span class="variable">Open</span><span class="operator">(</span> <span class="string">"LMachine"</span><span class="operator">,</span> <span class="operator">{</span><span class="string">Access</span><span class="operator">=></span><span class="variable">KEY_READ</span><span class="operator">(),</span><span class="string">Delimiter</span><span class="operator">=></span><span class="string">"/"</span><span class="operator">}</span> <span class="operator">)</span>
<span class="keyword">or</span> <span class="keyword">die</span> <span class="string">"Can't open HKEY_LOCAL_MACHINE key: $^E\n"</span><span class="operator">;</span>
<span class="variable">$swKey</span><span class="operator">=</span> <span class="variable">$machKey</span><span class="operator">-></span><span class="variable">Open</span><span class="operator">(</span> <span class="string">"Software"</span> <span class="operator">);</span>
<span class="variable">$logonKey</span><span class="operator">=</span> <span class="variable">$swKey</span><span class="operator">-></span><span class="variable">Open</span><span class="operator">(</span> <span class="string">"Microsoft/Windows NT/CurrentVersion/Winlogon/"</span> <span class="operator">);</span>
<span class="variable">$NTversKey</span><span class="operator">=</span> <span class="variable">$swKey</span><span class="operator">-></span><span class="variable">Open</span><span class="operator">(</span> <span class="operator">[</span><span class="string">"Microsoft"</span><span class="operator">,</span><span class="string">"Windows NT"</span><span class="operator">,</span><span class="string">"CurrentVersion"</span><span class="operator">]</span> <span class="operator">);</span>
<span class="variable">$versKey</span><span class="operator">=</span> <span class="variable">$swKey</span><span class="operator">-></span><span class="variable">Open</span><span class="operator">(</span> <span class="string">qw(Microsoft Windows CurrentVersion)</span> <span class="operator">);</span>
</pre>
</dd>
<dd>
<pre>
<span class="variable">$remoteKey</span><span class="operator">=</span> <span class="variable">$Registry</span><span class="operator">-></span><span class="variable">Open</span><span class="operator">(</span> <span class="string">"//HostA/LMachine/System/"</span><span class="operator">,</span> <span class="operator">{</span><span class="string">Delimiter</span><span class="operator">=></span><span class="string">"/"</span><span class="operator">}</span> <span class="operator">)</span>
<span class="keyword">or</span> <span class="keyword">die</span> <span class="string">"Can't connect to HostA or can't open subkey: $^E\n"</span><span class="operator">;</span>
</pre>
</dd>
</li>
<dt><strong><a name="item_clone">Clone</a></strong>
<dt><strong>$copy= $key->Clone</strong>
<dd>
<p>Creates a new object that is associated with the same Registry key
as the invoking object.</p>
</dd>
</li>
<dt><strong><a name="item_connect">Connect</a></strong>
<dt><strong>$remoteKey= $Registry->Connect( $sMachineName, $sKeyPath, $rhOptions )</strong>
<dd>
<p>The <a href="#item_connect"><code>Connect</code></a> method connects to the Registry of a remote machine,
and opens a key within it, then returns a new <em>Win32::TieRegistry</em>
object associated with that remote Registry key. If <a href="#item_connect"><code>Connect</code></a>
was called using a reference to a tied hash, then the return value
will also be a reference to a tied hash [or <a href="../../lib/Pod/perlfunc.html#item_undef"><code>undef</code></a>]. Otherwise,
if you wish to use the returned object as a tied hash [not just as
an object], then use the <a href="#item_tiedref"><code>TiedRef</code></a> method function after <a href="#item_connect"><code>Connect</code></a>.</p>
</dd>
<dd>
<p><code>$sMachineName</code> is the name of the remote machine. You don't have
to preceed the machine name with two delimiter characters.</p>
</dd>
<dd>
<p><code>$sKeyPath</code> is a string specifying the remote key to be opened.
Alternately <code>$sKeyPath</code> can be a reference to an array value
containing the list of increasingly deep keys specifying the path
to the key to be opened.</p>
</dd>
<dd>
<p><code>$rhOptions</code> is an optional reference to a hash containing extra
options. The <a href="#item_connect"><code>Connect</code></a> method supports two options, <code>"Delimiter"</code>
and <code>"Access"</code>. See the <a href="#item_open"><code>Open</code></a> method documentation for more
information on these options.</p>
</dd>
<dd>
<p><code>$sKeyPath</code> is already relative to the virtual root of the Registry
of the remote machine. A single leading delimiter on <code>sKeyPath</code>
will be ignored and is not required.</p>
</dd>
<dd>
<p><code>$sKeyPath</code> can be empty in which case <a href="#item_connect"><code>Connect</code></a> will return an
object representing the virtual root key of the remote Registry.
Each subsequent use of <a href="#item_open"><code>Open</code></a> on this virtual root key will call
the system <code>RegConnectRegistry</code> function.</p>
</dd>
<dd>
<p>The <a href="#item_connect"><code>Connect</code></a> method can be called via any <em>Win32::TieRegistry</em>
object, not just <code>$Registry</code>. Attributes such as the desired
level of access and the delimiter will be inherited from the
object used but the <code>$sKeyPath</code> will always be relative to the
virtual root of the remote machine's registry.</p>
</dd>
<dd>
<p>Examples:</p>
</dd>
<dd>
<pre>
<span class="variable">$remMachKey</span><span class="operator">=</span> <span class="variable">$Registry</span><span class="operator">-></span><span class="variable">Connect</span><span class="operator">(</span> <span class="string">"HostA"</span><span class="operator">,</span> <span class="string">"LMachine"</span><span class="operator">,</span> <span class="operator">{</span><span class="variable">Delimiter</span><span class="operator">-></span>"<span class="operator">/</span><span class="string">"} )
or die "</span><span class="variable">Can't</span> <span class="keyword">connect</span> <span class="variable">to</span> <span class="variable">HostA's</span> <span class="variable">HKEY_LOCAL_MACHINE</span> <span class="variable">key</span><span class="operator">:</span> <span class="variable">$^E</span><span class="operator">\</span><span class="variable">n</span><span class="string">";
</span>
</pre>
</dd>
<dd>
<pre>
<span class="variable">$remVersKey</span><span class="operator">=</span> <span class="variable">$remMachKey</span><span class="operator">-></span><span class="variable">Connect</span><span class="operator">(</span> <span class="string">"www.microsoft.com"</span><span class="operator">,</span>
<span class="string">"LMachine/Software/Microsoft/Inetsrv/CurrentVersion/"</span><span class="operator">,</span>
<span class="operator">{</span> <span class="string">Access</span><span class="operator">=></span><span class="variable">KEY_READ</span><span class="operator">,</span> <span class="string">Delimiter</span><sp
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?