module--winreg.html

来自「一本很好的python的说明书,适合对python感兴趣的人」· HTML 代码 · 共 533 行 · 第 1/2 页

HTML
533
字号

<P>
The Win32 documentation implies <var>key</var> must be in the 
 <tt class="constant">HKEY_USER</tt> or <tt class="constant">HKEY_LOCAL_MACHINE</tt> tree.
 This may or may not be true.
</dl>

<P>
<dl><dt><b><a name='l2h-3302'><tt class='function'>OpenKey</tt></a></b> (<var>key, sub_key</var><big>[</big><var>, res<code> = 0</code></var><big>]</big><big>[</big><var>, sam<code> = <tt class="constant">KEY_READ</tt></code></var><big>]</big>)
<dd>
  Opens the specified key, returning a <i class="dfn">handle object</i>

<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 identifies the sub_key to open

<P>
<var>res</var> is a reserved integer, and must be zero.  The default is zero.

<P>
<var>sam</var> is an integer that specifies an access mask that describes 
 the desired security access for the key.  Default is <tt class="constant">KEY_READ</tt>

<P>
The result is a new handle to the specified key

<P>
If the function fails, <tt class="exception">EnvironmentError</tt> is raised.
</dl>

<P>
<dl><dt><b><a name='l2h-3303'><tt class='function'>OpenKeyEx</tt></a></b> ()
<dd>
  The functionality of <tt class="function">OpenKeyEx()</tt> is provided via
  <tt class="function">OpenKey()</tt>, by the use of default arguments.
</dl>

<P>
<dl><dt><b><a name='l2h-3304'><tt class='function'>QueryInfoKey</tt></a></b> (<var>key</var>)
<dd>
 Returns information about a key, as a tuple.

<P>
<var>key</var> is an already open key, or one of the predefined 
 <tt class="constant">HKEY_*</tt> constants.

<P>
The result is a tuple of 3 items:
 [num_subkeys]
 An integer that identifies the number of sub keys this key has.
 [num_values]
 An integer that identifies the number of values this key has.
 [last_modified]
 A long integer that identifies when the key was last modified (if available)
 as 100's of nanoseconds since Jan 1, 1600.
</dl>

<P>
<dl><dt><b><a name='l2h-3305'><tt class='function'>QueryValue</tt></a></b> (<var>key, sub_key</var>)
<dd>
 Retrieves the unnamed value for a key, as a string

<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 holds the name of the subkey with which 
 the value is associated.  If this parameter is <code>None</code> or empty, the 
 function retrieves the value set by the <tt class="function">SetValue()</tt> method 
 for the key identified by <var>key</var>.

<P>
Values in the registry have name, type, and data components. This 
 method retrieves the data for a key's first value that has a NULL name.
 But the underlying API call doesn't return the type, Lame Lame Lame,
 DO NOT USE THIS!!!
</dl>

<P>
<dl><dt><b><a name='l2h-3306'><tt class='function'>QueryValueEx</tt></a></b> (<var>key, value_name</var>)
<dd>
  Retrieves the type and data for a specified value name associated with 
  an open 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_name</var> is a string indicating the value to query.

<P>
The result is a tuple of 2 items:
 [value]
 The value of the registry item.
 [type_id]
 An integer that identifies the registry type for this value.
</dl>

<P>
<dl><dt><b><a name='l2h-3307'><tt class='function'>SaveKey</tt></a></b> (<var>key, file_name</var>)
<dd>
  Saves the specified key, and all its subkeys to the specified file.

<P>
<var>key</var> is an already open key, or one of the predefined 
 <tt class="constant">HKEY_*</tt> constants.

<P>
<var>file_name</var> is the name of the file to save registry data to.
  This file cannot already exist. If this filename includes an extension,
  it cannot be used on file allocation table (FAT) file systems by the
  <tt class="method">LoadKey()</tt>, <tt class="method">ReplaceKey()</tt> or 
  <tt class="method">RestoreKey()</tt> methods.

<P>
If <var>key</var> represents a key on a remote computer, the path 
 described by <var>file_name</var> is relative to the remote computer.
 The caller of this method must possess the <tt class="constant">SeBackupPrivilege</tt> 
 security privilege.  Note that privileges are different than permissions 
 - see the Win32 documentation for more details.

<P>
This function passes NULL for <var>security_attributes</var> to the API.
</dl>

<P>
<dl><dt><b><a name='l2h-3308'><tt class='function'>SetValue</tt></a></b> (<var>key, sub_key, type, value</var>)
<dd>
 Associates a value with a specified key.

<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 subkey with which the value 
 is associated.

<P>
<var>type</var> is an integer that specifies the type of the data.  Currently this
 must be <tt class="constant">REG_SZ</tt>, meaning only strings are supported.
 Use the <tt class="function">SetValueEx()</tt> function for support for other data types.

<P>
<var>value</var> is a string that specifies the new value.

<P>
If the key specified by the <var>sub_key</var> parameter does not exist, 
 the SetValue function creates it.

<P>
Value lengths are limited by available memory. Long values (more than
 2048 bytes) should be stored as files with the filenames stored in 
 the configuration registry.  This helps the registry perform efficiently.

<P>
The key identified by the <var>key</var> parameter must have been 
 opened with <tt class="constant">KEY_SET_VALUE</tt> access.
</dl>

<P>
<dl><dt><b><a name='l2h-3309'><tt class='function'>SetValueEx</tt></a></b> (<var>key, value_name, reserved, type, value</var>)
<dd>
  Stores data in the value field of an open registry key.

<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 subkey with which the 
 value is associated.

<P>
<var>type</var> is an integer that specifies the type of the data.  
 This should be one of:
 [<tt class="constant">REG_BINARY</tt>] 
 	Binary data in any form.
 [<tt class="constant">REG_DWORD</tt>]
	A 32-bit number.
 [<tt class="constant">REG_DWORD_LITTLE_ENDIAN</tt>]
 	A 32-bit number in little-endian format.
 [<tt class="constant">REG_DWORD_BIG_ENDIAN</tt>]
	A 32-bit number in big-endian format.
 [<tt class="constant">REG_EXPAND_SZ</tt>]
 	A null-terminated string that contains unexpanded references
	to environment variables (for example, <code>%PATH%</code>)
 [<tt class="constant">REG_LINK</tt>]
 	A Unicode symbolic link.
 [<tt class="constant">REG_MULTI_SZ</tt>]
	A sequence (eg, list, sequence) of null-terminated strings, 
	terminated by two null characters. (Note that Python handles 
	this termination automatically)
 [<tt class="constant">REG_NONE</tt>]
	No defined value type.
 [<tt class="constant">REG_RESOURCE_LIST</tt>]
	A device-driver resource list.
 [<tt class="constant">REG_SZ</tt>]
 	A null-terminated string.

<P>
<var>reserved</var> can be anything - zero is always passed to the 
 API.

<P>
<var>value</var> is a string that specifies the new value.

<P>
This method can also set additional value and type information for the
 specified key.  The key identified by the key parameter must have been
 opened with <tt class="constant">KEY_SET_VALUE</tt> access.

<P>
To open the key, use the <tt class="function">CreateKeyEx()</tt> or 
 <tt class="function">OpenKey()</tt> methods.

<P>
Value lengths are limited by available memory. Long values (more than
 2048 bytes) should be stored as files with the filenames stored in
 the configuration registry.  This helps the registry perform efficiently.
</dl>

<P>

<p><hr>
<!--Table of Child-Links-->
<A NAME="CHILD_LINKS"><STRONG>Subsections</STRONG></A>

<UL>
<LI><A NAME="tex2html5936"
  href="handle-object.html" tppabs="http://www.python.org/doc/current/lib/handle-object.html">20.2.1 Registry handle objects </A>
</UL>
<!--End of Table of Child-Links-->

<DIV CLASS="navigation"><p><hr><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>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
<hr>See <i><a href="about.html" tppabs="http://www.python.org/doc/current/lib/about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>

⌨️ 快捷键说明

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