📄 module--winreg.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>20.2 _winreg - Windows registry access</title>
<META NAME="description" CONTENT="20.2 _winreg - Windows registry access">
<META NAME="keywords" CONTENT="lib">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="STYLESHEET" href="lib.css" tppabs="http://www.python.org/doc/current/lib/lib.css">
<LINK REL="next" href="module-winsound.html" tppabs="http://www.python.org/doc/current/lib/module-winsound.html">
<LINK REL="previous" href="module-msvcrt.html" tppabs="http://www.python.org/doc/current/lib/module-msvcrt.html">
<LINK REL="up" HREF="node413.html" tppabs="http://www.python.org/doc/current/lib/node413.html">
<LINK REL="next" href="handle-object.html" tppabs="http://www.python.org/doc/current/lib/handle-object.html">
</head>
<body>
<DIV CLASS="navigation"><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="msvcrt-other.html" tppabs="http://www.python.org/doc/current/lib/msvcrt-other.html"><img src="previous.gif" tppabs="http://www.python.org/doc/current/icons/previous.gif" border="0" height="32"
alt="Previous Page" width="32"></A></td>
<td><A HREF="node413.html" tppabs="http://www.python.org/doc/current/lib/node413.html"><img src="up.gif" tppabs="http://www.python.org/doc/current/icons/up.gif" border="0" height="32"
alt="Up One Level" width="32"></A></td>
<td><A href="handle-object.html" tppabs="http://www.python.org/doc/current/lib/handle-object.html"><img src="next.gif" tppabs="http://www.python.org/doc/current/icons/next.gif" border="0" height="32"
alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td><A href="contents.html" tppabs="http://www.python.org/doc/current/lib/contents.html"><img src="contents.gif" tppabs="http://www.python.org/doc/current/icons/contents.gif" border="0" height="32"
alt="Contents" width="32"></A></td>
<td><a href="modindex.html" tppabs="http://www.python.org/doc/current/lib/modindex.html" title="Module Index"><img src="modules.gif" tppabs="http://www.python.org/doc/current/icons/modules.gif" border="0" height="32"
alt="Module Index" width="32"></a></td>
<td><A href="genindex.html" tppabs="http://www.python.org/doc/current/lib/genindex.html"><img src="index.gif" tppabs="http://www.python.org/doc/current/icons/index.gif" border="0" height="32"
alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="msvcrt-other.html" tppabs="http://www.python.org/doc/current/lib/msvcrt-other.html">20.1.3 Other Functions</A>
<b class="navlabel">Up:</b> <a class="sectref" HREF="node413.html" tppabs="http://www.python.org/doc/current/lib/node413.html">20. MS Windows Specific</A>
<b class="navlabel">Next:</b> <a class="sectref" href="handle-object.html" tppabs="http://www.python.org/doc/current/lib/handle-object.html">20.2.1 Registry handle objects</A>
<br><hr></DIV>
<!--End of Navigation Panel-->
<H1><A NAME="SECTION0022200000000000000000">
20.2 <tt class="module">_winreg</tt> -
Windows registry access</A>
</H1>
<P>
<p class='availability'>Availability: <span
class='platform'>Windows</span>.</p>
<P>
New in version 2.0.
<P>
These functions expose the Windows registry API to Python. Instead of
using an integer as the registry handle, a handle object is used to
ensure that the handles are closed correctly, even if the programmer
neglects to explicitly close them.
<P>
This module exposes a very low-level interface to the Windows
registry; it is expected that in the future a new <code>winreg</code>
module will be created offering a higher-level interface to the
registry API.
<P>
This module offers the following functions:
<P>
<dl><dt><b><a name='l2h-3293'><tt class='function'>CloseKey</tt></a></b> (<var>hkey</var>)
<dd>
Closes a previously opened registry key.
The hkey argument specifies a previously opened key.
<P>
Note that if <var>hkey</var> is not closed using this method, (or the
<tt class="method">handle.Close()</tt> closed when the <var>hkey</var> object is
destroyed by Python.
</dl>
<P>
<dl><dt><b><a name='l2h-3294'><tt class='function'>ConnectRegistry</tt></a></b> (<var>computer_name, key</var>)
<dd>
Establishes a connection to a predefined registry handle on
another computer, and returns a <i class="dfn">handle object</i>
<P>
<var>computer_name</var> is the name of the remote computer, of the
form "<tt class="samp">\\computername</tt>". If <code>None</code>, the local computer
is used.
<P>
<var>key</var> is the predefined handle to connect to.
<P>
The return value is the handle of the opened key.
If the function fails, an <tt class="exception">EnvironmentError</tt> exception is
raised.
</dl>
<P>
<dl><dt><b><a name='l2h-3295'><tt class='function'>CreateKey</tt></a></b> (<var>key, sub_key</var>)
<dd>
Creates or opens the specified key, returning a <i class="dfn">handle object</i>
<P>
<var>key</var> is an already open key, or one of the predefined
<tt class="constant">HKEY_*</tt> constants.
<P>
<var>sub_key</var> is a string that names the key this method opens
or creates.
<P>
If <var>key</var> is one of the predefined keys, <var>sub_key</var> may
be <code>None</code>. In that case, the handle returned is the same key handle
passed in to the function.
<P>
If the key already exists, this function opens the existing key
<P>
The return value is the handle of the opened key.
If the function fails, an <tt class="exception">EnvironmentError</tt> exception is
raised.
</dl>
<P>
<dl><dt><b><a name='l2h-3296'><tt class='function'>DeleteKey</tt></a></b> (<var>key, sub_key</var>)
<dd>
Deletes the specified key.
<P>
<var>key</var> is an already open key, or any one of the predefined
<tt class="constant">HKEY_*</tt> constants.
<P>
<var>sub_key</var> is a string that must be a subkey of the key
identified by the <var>key</var> parameter. This value must not be
<code>None</code>, and the key may not have subkeys.
<P>
<i>This method can not delete keys with subkeys.</i>
<P>
If the method succeeds, the entire key, including all of its values,
is removed. If the method fails, an <tt class="exception">EnvironmentError</tt>
exception is raised.
</dl>
<P>
<dl><dt><b><a name='l2h-3297'><tt class='function'>DeleteValue</tt></a></b> (<var>key, value</var>)
<dd>
Removes a named value from a registry key.
<P>
<var>key</var> is an already open key, or one of the predefined
<tt class="constant">HKEY_*</tt> constants.
<P>
<var>value</var> is a string that identifies the value to remove.
</dl>
<P>
<dl><dt><b><a name='l2h-3298'><tt class='function'>EnumKey</tt></a></b> (<var>key, index</var>)
<dd>
Enumerates subkeys of an open registry key, returning a string.
<P>
<var>key</var> is an already open key, or any one of the predefined
<tt class="constant">HKEY_*</tt> constants.
<P>
<var>index</var> is an integer that identifies the index of the key to
retrieve.
<P>
The function retrieves the name of one subkey each time it
is called. It is typically called repeatedly until an
<tt class="exception">EnvironmentError</tt> exception
is raised, indicating, no more values are available.
</dl>
<P>
<dl><dt><b><a name='l2h-3299'><tt class='function'>EnumValue</tt></a></b> (<var>key, index</var>)
<dd>
Enumerates values of an open registry key, returning a tuple.
<P>
<var>key</var> is an already open key, or any one of the predefined
<tt class="constant">HKEY_*</tt> constants.
<P>
<var>index</var> is an integer that identifies the index of the value
to retrieve.
<P>
The function retrieves the name of one subkey each time it is
called. It is typically called repeatedly, until an
<tt class="exception">EnvironmentError</tt> exception is raised, indicating
no more values.
<P>
The result is a tuple of 3 items:
[value_name]
A string that identifies the value name
[value_data]
An object that holds the value data, and whose type depends
on the underlying registry type.
[data_type] is an integer that identifies the type of the
value data.
<P>
</dl>
<P>
<dl><dt><b><a name='l2h-3300'><tt class='function'>FlushKey</tt></a></b> (<var>key</var>)
<dd>
Writes all the attributes of a key to the registry.
<P>
<var>key</var> is an already open key, or one of the predefined
<tt class="constant">HKEY_*</tt> constants.
<P>
It is not necessary to call RegFlushKey to change a key.
Registry changes are flushed to disk by the registry using its lazy
flusher. Registry changes are also flushed to disk at system
shutdown. Unlike <tt class="function">CloseKey()</tt>, the <tt class="function">FlushKey()</tt> method
returns only when all the data has been written to the registry.
An application should only call <tt class="function">FlushKey()</tt> if it requires absolute
certainty that registry changes are on disk.
<P>
<i>If you don't know whether a <tt class="function">FlushKey()</tt> call is required, it
probably isn't.</i>
<P>
</dl>
<P>
<dl><dt><b><a name='l2h-3301'><tt class='function'>RegLoadKey</tt></a></b> (<var>key, sub_key, file_name</var>)
<dd>
Creates a subkey under the specified key and stores registration
information from a specified file into that subkey.
<P>
<var>key</var> is an already open key, or any of the predefined
<tt class="constant">HKEY_*</tt> constants.
<P>
<var>sub_key</var> is a string that identifies the sub_key to load
<P>
<var>file_name</var> is the name of the file to load registry data from.
This file must have been created with the <tt class="function">SaveKey()</tt> function.
Under the file allocation table (FAT) file system, the filename may not
have an extension.
<P>
A call to LoadKey() fails if the calling process does not have the
<tt class="constant">SE_RESTORE_PRIVILEGE</tt> privilege. Note that privileges
are different than permissions - see the Win32 documentation for
more details.
<P>
If <var>key</var> is a handle returned by <tt class="function">ConnectRegistry()</tt>,
then the path specified in <var>fileName</var> is relative to the
remote computer.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -