gooderp18绿色标准版
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

1103 lines
92KB

  1. <!DOCTYPE html>
  2. <html lang="en" data-content_root="../">
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
  6. <meta property="og:title" content="winreg — Windows registry access" />
  7. <meta property="og:type" content="website" />
  8. <meta property="og:url" content="https://docs.python.org/3/library/winreg.html" />
  9. <meta property="og:site_name" content="Python documentation" />
  10. <meta property="og:description" content="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 p..." />
  11. <meta property="og:image" content="https://docs.python.org/3/_static/og-image.png" />
  12. <meta property="og:image:alt" content="Python documentation" />
  13. <meta name="description" content="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 p..." />
  14. <meta property="og:image:width" content="200" />
  15. <meta property="og:image:height" content="200" />
  16. <meta name="theme-color" content="#3776ab" />
  17. <title>winreg — Windows registry access &#8212; Python 3.12.3 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
  18. <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=80d5e7a1" />
  19. <link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=bb723527" />
  20. <link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=b20cc3f5" />
  21. <script src="../_static/documentation_options.js?v=2c828074"></script>
  22. <script src="../_static/doctools.js?v=888ff710"></script>
  23. <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
  24. <script src="../_static/sidebar.js"></script>
  25. <link rel="search" type="application/opensearchdescription+xml"
  26. title="Search within Python 3.12.3 documentation"
  27. href="../_static/opensearch.xml"/>
  28. <link rel="author" title="About these documents" href="../about.html" />
  29. <link rel="index" title="Index" href="../genindex.html" />
  30. <link rel="search" title="Search" href="../search.html" />
  31. <link rel="copyright" title="Copyright" href="../copyright.html" />
  32. <link rel="next" title="winsound — Sound-playing interface for Windows" href="winsound.html" />
  33. <link rel="prev" title="msvcrt — Useful routines from the MS VC++ runtime" href="msvcrt.html" />
  34. <link rel="canonical" href="https://docs.python.org/3/library/winreg.html" />
  35. <style>
  36. @media only screen {
  37. table.full-width-table {
  38. width: 100%;
  39. }
  40. }
  41. </style>
  42. <link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">
  43. <link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
  44. <script type="text/javascript" src="../_static/copybutton.js"></script>
  45. <script type="text/javascript" src="../_static/menu.js"></script>
  46. <script type="text/javascript" src="../_static/search-focus.js"></script>
  47. <script type="text/javascript" src="../_static/themetoggle.js"></script>
  48. </head>
  49. <body>
  50. <div class="mobile-nav">
  51. <input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
  52. aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
  53. <nav class="nav-content" role="navigation">
  54. <label for="menuToggler" class="toggler__label">
  55. <span></span>
  56. </label>
  57. <span class="nav-items-wrapper">
  58. <a href="https://www.python.org/" class="nav-logo">
  59. <img src="../_static/py.svg" alt="Python logo"/>
  60. </a>
  61. <span class="version_switcher_placeholder"></span>
  62. <form role="search" class="search" action="../search.html" method="get">
  63. <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
  64. <path fill-rule="nonzero" fill="currentColor" d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"></path>
  65. </svg>
  66. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" />
  67. <input type="submit" value="Go"/>
  68. </form>
  69. </span>
  70. </nav>
  71. <div class="menu-wrapper">
  72. <nav class="menu" role="navigation" aria-label="main navigation">
  73. <div class="language_switcher_placeholder"></div>
  74. <label class="theme-selector-label">
  75. Theme
  76. <select class="theme-selector" oninput="activateTheme(this.value)">
  77. <option value="auto" selected>Auto</option>
  78. <option value="light">Light</option>
  79. <option value="dark">Dark</option>
  80. </select>
  81. </label>
  82. <div>
  83. <h3><a href="../contents.html">Table of Contents</a></h3>
  84. <ul>
  85. <li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">winreg</span></code> — Windows registry access</a><ul>
  86. <li><a class="reference internal" href="#functions">Functions</a></li>
  87. <li><a class="reference internal" href="#constants">Constants</a><ul>
  88. <li><a class="reference internal" href="#hkey-constants">HKEY_* Constants</a></li>
  89. <li><a class="reference internal" href="#access-rights">Access Rights</a><ul>
  90. <li><a class="reference internal" href="#bit-specific">64-bit Specific</a></li>
  91. </ul>
  92. </li>
  93. <li><a class="reference internal" href="#value-types">Value Types</a></li>
  94. </ul>
  95. </li>
  96. <li><a class="reference internal" href="#registry-handle-objects">Registry Handle Objects</a></li>
  97. </ul>
  98. </li>
  99. </ul>
  100. </div>
  101. <div>
  102. <h4>Previous topic</h4>
  103. <p class="topless"><a href="msvcrt.html"
  104. title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">msvcrt</span></code> — Useful routines from the MS VC++ runtime</a></p>
  105. </div>
  106. <div>
  107. <h4>Next topic</h4>
  108. <p class="topless"><a href="winsound.html"
  109. title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">winsound</span></code> — Sound-playing interface for Windows</a></p>
  110. </div>
  111. <div role="note" aria-label="source link">
  112. <h3>This Page</h3>
  113. <ul class="this-page-menu">
  114. <li><a href="../bugs.html">Report a Bug</a></li>
  115. <li>
  116. <a href="https://github.com/python/cpython/blob/main/Doc/library/winreg.rst"
  117. rel="nofollow">Show Source
  118. </a>
  119. </li>
  120. </ul>
  121. </div>
  122. </nav>
  123. </div>
  124. </div>
  125. <div class="related" role="navigation" aria-label="related navigation">
  126. <h3>Navigation</h3>
  127. <ul>
  128. <li class="right" style="margin-right: 10px">
  129. <a href="../genindex.html" title="General Index"
  130. accesskey="I">index</a></li>
  131. <li class="right" >
  132. <a href="../py-modindex.html" title="Python Module Index"
  133. >modules</a> |</li>
  134. <li class="right" >
  135. <a href="winsound.html" title="winsound — Sound-playing interface for Windows"
  136. accesskey="N">next</a> |</li>
  137. <li class="right" >
  138. <a href="msvcrt.html" title="msvcrt — Useful routines from the MS VC++ runtime"
  139. accesskey="P">previous</a> |</li>
  140. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  141. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  142. <li class="switchers">
  143. <div class="language_switcher_placeholder"></div>
  144. <div class="version_switcher_placeholder"></div>
  145. </li>
  146. <li>
  147. </li>
  148. <li id="cpython-language-and-version">
  149. <a href="../index.html">3.12.3 Documentation</a> &#187;
  150. </li>
  151. <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
  152. <li class="nav-item nav-item-2"><a href="windows.html" accesskey="U">MS Windows Specific Services</a> &#187;</li>
  153. <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">winreg</span></code> — Windows registry access</a></li>
  154. <li class="right">
  155. <div class="inline-search" role="search">
  156. <form class="inline-search" action="../search.html" method="get">
  157. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  158. <input type="submit" value="Go" />
  159. </form>
  160. </div>
  161. |
  162. </li>
  163. <li class="right">
  164. <label class="theme-selector-label">
  165. Theme
  166. <select class="theme-selector" oninput="activateTheme(this.value)">
  167. <option value="auto" selected>Auto</option>
  168. <option value="light">Light</option>
  169. <option value="dark">Dark</option>
  170. </select>
  171. </label> |</li>
  172. </ul>
  173. </div>
  174. <div class="document">
  175. <div class="documentwrapper">
  176. <div class="bodywrapper">
  177. <div class="body" role="main">
  178. <section id="module-winreg">
  179. <span id="winreg-windows-registry-access"></span><h1><a class="reference internal" href="#module-winreg" title="winreg: Routines and objects for manipulating the Windows registry. (Windows)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">winreg</span></code></a> — Windows registry access<a class="headerlink" href="#module-winreg" title="Link to this heading">¶</a></h1>
  180. <hr class="docutils" />
  181. <p>These functions expose the Windows registry API to Python. Instead of using an
  182. integer as the registry handle, a <a class="reference internal" href="#handle-object"><span class="std std-ref">handle object</span></a> is used
  183. to ensure that the handles are closed correctly, even if the programmer neglects
  184. to explicitly close them.</p>
  185. <div class="versionchanged" id="exception-changed">
  186. <p><span class="versionmodified changed">Changed in version 3.3: </span>Several functions in this module used to raise a
  187. <a class="reference internal" href="exceptions.html#WindowsError" title="WindowsError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">WindowsError</span></code></a>, which is now an alias of <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a>.</p>
  188. </div>
  189. <section id="functions">
  190. <span id="id1"></span><h2>Functions<a class="headerlink" href="#functions" title="Link to this heading">¶</a></h2>
  191. <p>This module offers the following functions:</p>
  192. <dl class="py function">
  193. <dt class="sig sig-object py" id="winreg.CloseKey">
  194. <span class="sig-prename descclassname"><span class="pre">winreg.</span></span><span class="sig-name descname"><span class="pre">CloseKey</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">hkey</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#winreg.CloseKey" title="Link to this definition">¶</a></dt>
  195. <dd><p>Closes a previously opened registry key. The <em>hkey</em> argument specifies a
  196. previously opened key.</p>
  197. <div class="admonition note">
  198. <p class="admonition-title">Note</p>
  199. <p>If <em>hkey</em> is not closed using this method (or via <a class="reference internal" href="#winreg.PyHKEY.Close" title="winreg.PyHKEY.Close"><code class="xref py py-meth docutils literal notranslate"><span class="pre">hkey.Close()</span></code></a>), it is closed when the <em>hkey</em> object is destroyed by
  200. Python.</p>
  201. </div>
  202. </dd></dl>
  203. <dl class="py function">
  204. <dt class="sig sig-object py" id="winreg.ConnectRegistry">
  205. <span class="sig-prename descclassname"><span class="pre">winreg.</span></span><span class="sig-name descname"><span class="pre">ConnectRegistry</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">computer_name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">key</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#winreg.ConnectRegistry" title="Link to this definition">¶</a></dt>
  206. <dd><p>Establishes a connection to a predefined registry handle on another computer,
  207. and returns a <a class="reference internal" href="#handle-object"><span class="std std-ref">handle object</span></a>.</p>
  208. <p><em>computer_name</em> is the name of the remote computer, of the form
  209. <code class="docutils literal notranslate"><span class="pre">r&quot;\\computername&quot;</span></code>. If <code class="docutils literal notranslate"><span class="pre">None</span></code>, the local computer is used.</p>
  210. <p><em>key</em> is the predefined handle to connect to.</p>
  211. <p>The return value is the handle of the opened key. If the function fails, an
  212. <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> exception is raised.</p>
  213. <p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">winreg.ConnectRegistry</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">computer_name</span></code>, <code class="docutils literal notranslate"><span class="pre">key</span></code>.</p>
  214. <div class="versionchanged">
  215. <p><span class="versionmodified changed">Changed in version 3.3: </span>See <a class="reference internal" href="#exception-changed"><span class="std std-ref">above</span></a>.</p>
  216. </div>
  217. </dd></dl>
  218. <dl class="py function">
  219. <dt class="sig sig-object py" id="winreg.CreateKey">
  220. <span class="sig-prename descclassname"><span class="pre">winreg.</span></span><span class="sig-name descname"><span class="pre">CreateKey</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">key</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">sub_key</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#winreg.CreateKey" title="Link to this definition">¶</a></dt>
  221. <dd><p>Creates or opens the specified key, returning a
  222. <a class="reference internal" href="#handle-object"><span class="std std-ref">handle object</span></a>.</p>
  223. <p><em>key</em> is an already open key, or one of the predefined
  224. <a class="reference internal" href="#hkey-constants"><span class="std std-ref">HKEY_* constants</span></a>.</p>
  225. <p><em>sub_key</em> is a string that names the key this method opens or creates.</p>
  226. <p>If <em>key</em> is one of the predefined keys, <em>sub_key</em> may be <code class="docutils literal notranslate"><span class="pre">None</span></code>. In that
  227. case, the handle returned is the same key handle passed in to the function.</p>
  228. <p>If the key already exists, this function opens the existing key.</p>
  229. <p>The return value is the handle of the opened key. If the function fails, an
  230. <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> exception is raised.</p>
  231. <p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">winreg.CreateKey</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">key</span></code>, <code class="docutils literal notranslate"><span class="pre">sub_key</span></code>, <code class="docutils literal notranslate"><span class="pre">access</span></code>.</p>
  232. <p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">winreg.OpenKey/result</span></code> with argument <code class="docutils literal notranslate"><span class="pre">key</span></code>.</p>
  233. <div class="versionchanged">
  234. <p><span class="versionmodified changed">Changed in version 3.3: </span>See <a class="reference internal" href="#exception-changed"><span class="std std-ref">above</span></a>.</p>
  235. </div>
  236. </dd></dl>
  237. <dl class="py function">
  238. <dt class="sig sig-object py" id="winreg.CreateKeyEx">
  239. <span class="sig-prename descclassname"><span class="pre">winreg.</span></span><span class="sig-name descname"><span class="pre">CreateKeyEx</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">key</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">sub_key</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">reserved</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">access</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">KEY_WRITE</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#winreg.CreateKeyEx" title="Link to this definition">¶</a></dt>
  240. <dd><p>Creates or opens the specified key, returning a
  241. <a class="reference internal" href="#handle-object"><span class="std std-ref">handle object</span></a>.</p>
  242. <p><em>key</em> is an already open key, or one of the predefined
  243. <a class="reference internal" href="#hkey-constants"><span class="std std-ref">HKEY_* constants</span></a>.</p>
  244. <p><em>sub_key</em> is a string that names the key this method opens or creates.</p>
  245. <p><em>reserved</em> is a reserved integer, and must be zero. The default is zero.</p>
  246. <p><em>access</em> is an integer that specifies an access mask that describes the desired
  247. security access for the key. Default is <a class="reference internal" href="#winreg.KEY_WRITE" title="winreg.KEY_WRITE"><code class="xref py py-const docutils literal notranslate"><span class="pre">KEY_WRITE</span></code></a>. See
  248. <a class="reference internal" href="#access-rights"><span class="std std-ref">Access Rights</span></a> for other allowed values.</p>
  249. <p>If <em>key</em> is one of the predefined keys, <em>sub_key</em> may be <code class="docutils literal notranslate"><span class="pre">None</span></code>. In that
  250. case, the handle returned is the same key handle passed in to the function.</p>
  251. <p>If the key already exists, this function opens the existing key.</p>
  252. <p>The return value is the handle of the opened key. If the function fails, an
  253. <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> exception is raised.</p>
  254. <p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">winreg.CreateKey</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">key</span></code>, <code class="docutils literal notranslate"><span class="pre">sub_key</span></code>, <code class="docutils literal notranslate"><span class="pre">access</span></code>.</p>
  255. <p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">winreg.OpenKey/result</span></code> with argument <code class="docutils literal notranslate"><span class="pre">key</span></code>.</p>
  256. <div class="versionadded">
  257. <p><span class="versionmodified added">New in version 3.2.</span></p>
  258. </div>
  259. <div class="versionchanged">
  260. <p><span class="versionmodified changed">Changed in version 3.3: </span>See <a class="reference internal" href="#exception-changed"><span class="std std-ref">above</span></a>.</p>
  261. </div>
  262. </dd></dl>
  263. <dl class="py function">
  264. <dt class="sig sig-object py" id="winreg.DeleteKey">
  265. <span class="sig-prename descclassname"><span class="pre">winreg.</span></span><span class="sig-name descname"><span class="pre">DeleteKey</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">key</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">sub_key</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#winreg.DeleteKey" title="Link to this definition">¶</a></dt>
  266. <dd><p>Deletes the specified key.</p>
  267. <p><em>key</em> is an already open key, or one of the predefined
  268. <a class="reference internal" href="#hkey-constants"><span class="std std-ref">HKEY_* constants</span></a>.</p>
  269. <p><em>sub_key</em> is a string that must be a subkey of the key identified by the <em>key</em>
  270. parameter. This value must not be <code class="docutils literal notranslate"><span class="pre">None</span></code>, and the key may not have subkeys.</p>
  271. <p><em>This method can not delete keys with subkeys.</em></p>
  272. <p>If the method succeeds, the entire key, including all of its values, is removed.
  273. If the method fails, an <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> exception is raised.</p>
  274. <p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">winreg.DeleteKey</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">key</span></code>, <code class="docutils literal notranslate"><span class="pre">sub_key</span></code>, <code class="docutils literal notranslate"><span class="pre">access</span></code>.</p>
  275. <div class="versionchanged">
  276. <p><span class="versionmodified changed">Changed in version 3.3: </span>See <a class="reference internal" href="#exception-changed"><span class="std std-ref">above</span></a>.</p>
  277. </div>
  278. </dd></dl>
  279. <dl class="py function">
  280. <dt class="sig sig-object py" id="winreg.DeleteKeyEx">
  281. <span class="sig-prename descclassname"><span class="pre">winreg.</span></span><span class="sig-name descname"><span class="pre">DeleteKeyEx</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">key</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">sub_key</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">access</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">KEY_WOW64_64KEY</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">reserved</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#winreg.DeleteKeyEx" title="Link to this definition">¶</a></dt>
  282. <dd><p>Deletes the specified key.</p>
  283. <p><em>key</em> is an already open key, or one of the predefined
  284. <a class="reference internal" href="#hkey-constants"><span class="std std-ref">HKEY_* constants</span></a>.</p>
  285. <p><em>sub_key</em> is a string that must be a subkey of the key identified by the
  286. <em>key</em> parameter. This value must not be <code class="docutils literal notranslate"><span class="pre">None</span></code>, and the key may not have
  287. subkeys.</p>
  288. <p><em>reserved</em> is a reserved integer, and must be zero. The default is zero.</p>
  289. <p><em>access</em> is an integer that specifies an access mask that describes the
  290. desired security access for the key. Default is <a class="reference internal" href="#winreg.KEY_WOW64_64KEY" title="winreg.KEY_WOW64_64KEY"><code class="xref py py-const docutils literal notranslate"><span class="pre">KEY_WOW64_64KEY</span></code></a>.
  291. On 32-bit Windows, the WOW64 constants are ignored.
  292. See <a class="reference internal" href="#access-rights"><span class="std std-ref">Access Rights</span></a> for other allowed values.</p>
  293. <p><em>This method can not delete keys with subkeys.</em></p>
  294. <p>If the method succeeds, the entire key, including all of its values, is
  295. removed. If the method fails, an <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> exception is raised.</p>
  296. <p>On unsupported Windows versions, <a class="reference internal" href="exceptions.html#NotImplementedError" title="NotImplementedError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NotImplementedError</span></code></a> is raised.</p>
  297. <p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">winreg.DeleteKey</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">key</span></code>, <code class="docutils literal notranslate"><span class="pre">sub_key</span></code>, <code class="docutils literal notranslate"><span class="pre">access</span></code>.</p>
  298. <div class="versionadded">
  299. <p><span class="versionmodified added">New in version 3.2.</span></p>
  300. </div>
  301. <div class="versionchanged">
  302. <p><span class="versionmodified changed">Changed in version 3.3: </span>See <a class="reference internal" href="#exception-changed"><span class="std std-ref">above</span></a>.</p>
  303. </div>
  304. </dd></dl>
  305. <dl class="py function">
  306. <dt class="sig sig-object py" id="winreg.DeleteValue">
  307. <span class="sig-prename descclassname"><span class="pre">winreg.</span></span><span class="sig-name descname"><span class="pre">DeleteValue</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">key</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">value</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#winreg.DeleteValue" title="Link to this definition">¶</a></dt>
  308. <dd><p>Removes a named value from a registry key.</p>
  309. <p><em>key</em> is an already open key, or one of the predefined
  310. <a class="reference internal" href="#hkey-constants"><span class="std std-ref">HKEY_* constants</span></a>.</p>
  311. <p><em>value</em> is a string that identifies the value to remove.</p>
  312. <p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">winreg.DeleteValue</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">key</span></code>, <code class="docutils literal notranslate"><span class="pre">value</span></code>.</p>
  313. </dd></dl>
  314. <dl class="py function">
  315. <dt class="sig sig-object py" id="winreg.EnumKey">
  316. <span class="sig-prename descclassname"><span class="pre">winreg.</span></span><span class="sig-name descname"><span class="pre">EnumKey</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">key</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">index</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#winreg.EnumKey" title="Link to this definition">¶</a></dt>
  317. <dd><p>Enumerates subkeys of an open registry key, returning a string.</p>
  318. <p><em>key</em> is an already open key, or one of the predefined
  319. <a class="reference internal" href="#hkey-constants"><span class="std std-ref">HKEY_* constants</span></a>.</p>
  320. <p><em>index</em> is an integer that identifies the index of the key to retrieve.</p>
  321. <p>The function retrieves the name of one subkey each time it is called. It is
  322. typically called repeatedly until an <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> exception is
  323. raised, indicating, no more values are available.</p>
  324. <p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">winreg.EnumKey</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">key</span></code>, <code class="docutils literal notranslate"><span class="pre">index</span></code>.</p>
  325. <div class="versionchanged">
  326. <p><span class="versionmodified changed">Changed in version 3.3: </span>See <a class="reference internal" href="#exception-changed"><span class="std std-ref">above</span></a>.</p>
  327. </div>
  328. </dd></dl>
  329. <dl class="py function">
  330. <dt class="sig sig-object py" id="winreg.EnumValue">
  331. <span class="sig-prename descclassname"><span class="pre">winreg.</span></span><span class="sig-name descname"><span class="pre">EnumValue</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">key</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">index</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#winreg.EnumValue" title="Link to this definition">¶</a></dt>
  332. <dd><p>Enumerates values of an open registry key, returning a tuple.</p>
  333. <p><em>key</em> is an already open key, or one of the predefined
  334. <a class="reference internal" href="#hkey-constants"><span class="std std-ref">HKEY_* constants</span></a>.</p>
  335. <p><em>index</em> is an integer that identifies the index of the value to retrieve.</p>
  336. <p>The function retrieves the name of one subkey each time it is called. It is
  337. typically called repeatedly, until an <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> exception is
  338. raised, indicating no more values.</p>
  339. <p>The result is a tuple of 3 items:</p>
  340. <table class="docutils align-default">
  341. <thead>
  342. <tr class="row-odd"><th class="head"><p>Index</p></th>
  343. <th class="head"><p>Meaning</p></th>
  344. </tr>
  345. </thead>
  346. <tbody>
  347. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">0</span></code></p></td>
  348. <td><p>A string that identifies the value name</p></td>
  349. </tr>
  350. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">1</span></code></p></td>
  351. <td><p>An object that holds the value data, and
  352. whose type depends on the underlying
  353. registry type</p></td>
  354. </tr>
  355. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">2</span></code></p></td>
  356. <td><p>An integer that identifies the type of the
  357. value data (see table in docs for
  358. <a class="reference internal" href="#winreg.SetValueEx" title="winreg.SetValueEx"><code class="xref py py-meth docutils literal notranslate"><span class="pre">SetValueEx()</span></code></a>)</p></td>
  359. </tr>
  360. </tbody>
  361. </table>
  362. <p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">winreg.EnumValue</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">key</span></code>, <code class="docutils literal notranslate"><span class="pre">index</span></code>.</p>
  363. <div class="versionchanged">
  364. <p><span class="versionmodified changed">Changed in version 3.3: </span>See <a class="reference internal" href="#exception-changed"><span class="std std-ref">above</span></a>.</p>
  365. </div>
  366. </dd></dl>
  367. <dl class="py function" id="index-0">
  368. <dt class="sig sig-object py" id="winreg.ExpandEnvironmentStrings">
  369. <span class="sig-prename descclassname"><span class="pre">winreg.</span></span><span class="sig-name descname"><span class="pre">ExpandEnvironmentStrings</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">str</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#winreg.ExpandEnvironmentStrings" title="Link to this definition">¶</a></dt>
  370. <dd><p>Expands environment variable placeholders <code class="docutils literal notranslate"><span class="pre">%NAME%</span></code> in strings like
  371. <a class="reference internal" href="#winreg.REG_EXPAND_SZ" title="winreg.REG_EXPAND_SZ"><code class="xref py py-const docutils literal notranslate"><span class="pre">REG_EXPAND_SZ</span></code></a>:</p>
  372. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">ExpandEnvironmentStrings</span><span class="p">(</span><span class="s1">&#39;%windir%&#39;</span><span class="p">)</span>
  373. <span class="go">&#39;C:\\Windows&#39;</span>
  374. </pre></div>
  375. </div>
  376. <p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">winreg.ExpandEnvironmentStrings</span></code> with argument <code class="docutils literal notranslate"><span class="pre">str</span></code>.</p>
  377. </dd></dl>
  378. <dl class="py function">
  379. <dt class="sig sig-object py" id="winreg.FlushKey">
  380. <span class="sig-prename descclassname"><span class="pre">winreg.</span></span><span class="sig-name descname"><span class="pre">FlushKey</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">key</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#winreg.FlushKey" title="Link to this definition">¶</a></dt>
  381. <dd><p>Writes all the attributes of a key to the registry.</p>
  382. <p><em>key</em> is an already open key, or one of the predefined
  383. <a class="reference internal" href="#hkey-constants"><span class="std std-ref">HKEY_* constants</span></a>.</p>
  384. <p>It is not necessary to call <a class="reference internal" href="#winreg.FlushKey" title="winreg.FlushKey"><code class="xref py py-func docutils literal notranslate"><span class="pre">FlushKey()</span></code></a> to change a key. Registry changes are
  385. flushed to disk by the registry using its lazy flusher. Registry changes are
  386. also flushed to disk at system shutdown. Unlike <a class="reference internal" href="#winreg.CloseKey" title="winreg.CloseKey"><code class="xref py py-func docutils literal notranslate"><span class="pre">CloseKey()</span></code></a>, the
  387. <a class="reference internal" href="#winreg.FlushKey" title="winreg.FlushKey"><code class="xref py py-func docutils literal notranslate"><span class="pre">FlushKey()</span></code></a> method returns only when all the data has been written to the
  388. registry. An application should only call <a class="reference internal" href="#winreg.FlushKey" title="winreg.FlushKey"><code class="xref py py-func docutils literal notranslate"><span class="pre">FlushKey()</span></code></a> if it requires
  389. absolute certainty that registry changes are on disk.</p>
  390. <div class="admonition note">
  391. <p class="admonition-title">Note</p>
  392. <p>If you don’t know whether a <a class="reference internal" href="#winreg.FlushKey" title="winreg.FlushKey"><code class="xref py py-func docutils literal notranslate"><span class="pre">FlushKey()</span></code></a> call is required, it probably
  393. isn’t.</p>
  394. </div>
  395. </dd></dl>
  396. <dl class="py function">
  397. <dt class="sig sig-object py" id="winreg.LoadKey">
  398. <span class="sig-prename descclassname"><span class="pre">winreg.</span></span><span class="sig-name descname"><span class="pre">LoadKey</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">key</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">sub_key</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">file_name</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#winreg.LoadKey" title="Link to this definition">¶</a></dt>
  399. <dd><p>Creates a subkey under the specified key and stores registration information
  400. from a specified file into that subkey.</p>
  401. <p><em>key</em> is a handle returned by <a class="reference internal" href="#winreg.ConnectRegistry" title="winreg.ConnectRegistry"><code class="xref py py-func docutils literal notranslate"><span class="pre">ConnectRegistry()</span></code></a> or one of the constants
  402. <a class="reference internal" href="#winreg.HKEY_USERS" title="winreg.HKEY_USERS"><code class="xref py py-const docutils literal notranslate"><span class="pre">HKEY_USERS</span></code></a> or <a class="reference internal" href="#winreg.HKEY_LOCAL_MACHINE" title="winreg.HKEY_LOCAL_MACHINE"><code class="xref py py-const docutils literal notranslate"><span class="pre">HKEY_LOCAL_MACHINE</span></code></a>.</p>
  403. <p><em>sub_key</em> is a string that identifies the subkey to load.</p>
  404. <p><em>file_name</em> is the name of the file to load registry data from. This file must
  405. have been created with the <a class="reference internal" href="#winreg.SaveKey" title="winreg.SaveKey"><code class="xref py py-func docutils literal notranslate"><span class="pre">SaveKey()</span></code></a> function. Under the file allocation
  406. table (FAT) file system, the filename may not have an extension.</p>
  407. <p>A call to <a class="reference internal" href="#winreg.LoadKey" title="winreg.LoadKey"><code class="xref py py-func docutils literal notranslate"><span class="pre">LoadKey()</span></code></a> fails if the calling process does not have the
  408. <code class="xref c c-data docutils literal notranslate"><span class="pre">SE_RESTORE_PRIVILEGE</span></code> privilege. Note that privileges are different
  409. from permissions – see the <a class="reference external" href="https://msdn.microsoft.com/en-us/library/ms724889%28v=VS.85%29.aspx">RegLoadKey documentation</a> for
  410. more details.</p>
  411. <p>If <em>key</em> is a handle returned by <a class="reference internal" href="#winreg.ConnectRegistry" title="winreg.ConnectRegistry"><code class="xref py py-func docutils literal notranslate"><span class="pre">ConnectRegistry()</span></code></a>, then the path
  412. specified in <em>file_name</em> is relative to the remote computer.</p>
  413. <p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">winreg.LoadKey</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">key</span></code>, <code class="docutils literal notranslate"><span class="pre">sub_key</span></code>, <code class="docutils literal notranslate"><span class="pre">file_name</span></code>.</p>
  414. </dd></dl>
  415. <dl class="py function">
  416. <dt class="sig sig-object py" id="winreg.OpenKey">
  417. <span class="sig-prename descclassname"><span class="pre">winreg.</span></span><span class="sig-name descname"><span class="pre">OpenKey</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">key</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">sub_key</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">reserved</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">access</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">KEY_READ</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#winreg.OpenKey" title="Link to this definition">¶</a></dt>
  418. <dt class="sig sig-object py" id="winreg.OpenKeyEx">
  419. <span class="sig-prename descclassname"><span class="pre">winreg.</span></span><span class="sig-name descname"><span class="pre">OpenKeyEx</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">key</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">sub_key</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">reserved</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">access</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">KEY_READ</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#winreg.OpenKeyEx" title="Link to this definition">¶</a></dt>
  420. <dd><p>Opens the specified key, returning a <a class="reference internal" href="#handle-object"><span class="std std-ref">handle object</span></a>.</p>
  421. <p><em>key</em> is an already open key, or one of the predefined
  422. <a class="reference internal" href="#hkey-constants"><span class="std std-ref">HKEY_* constants</span></a>.</p>
  423. <p><em>sub_key</em> is a string that identifies the sub_key to open.</p>
  424. <p><em>reserved</em> is a reserved integer, and must be zero. The default is zero.</p>
  425. <p><em>access</em> is an integer that specifies an access mask that describes the desired
  426. security access for the key. Default is <a class="reference internal" href="#winreg.KEY_READ" title="winreg.KEY_READ"><code class="xref py py-const docutils literal notranslate"><span class="pre">KEY_READ</span></code></a>. See <a class="reference internal" href="#access-rights"><span class="std std-ref">Access
  427. Rights</span></a> for other allowed values.</p>
  428. <p>The result is a new handle to the specified key.</p>
  429. <p>If the function fails, <a class="reference internal" href="exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a> is raised.</p>
  430. <p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">winreg.OpenKey</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">key</span></code>, <code class="docutils literal notranslate"><span class="pre">sub_key</span></code>, <code class="docutils literal notranslate"><span class="pre">access</span></code>.</p>
  431. <p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">winreg.OpenKey/result</span></code> with argument <code class="docutils literal notranslate"><span class="pre">key</span></code>.</p>
  432. <div class="versionchanged">
  433. <p><span class="versionmodified changed">Changed in version 3.2: </span>Allow the use of named arguments.</p>
  434. </div>
  435. <div class="versionchanged">
  436. <p><span class="versionmodified changed">Changed in version 3.3: </span>See <a class="reference internal" href="#exception-changed"><span class="std std-ref">above</span></a>.</p>
  437. </div>
  438. </dd></dl>
  439. <dl class="py function">
  440. <dt class="sig sig-object py" id="winreg.QueryInfoKey">
  441. <span class="sig-prename descclassname"><span class="pre">winreg.</span></span><span class="sig-name descname"><span class="pre">QueryInfoKey</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">key</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#winreg.QueryInfoKey" title="Link to this definition">¶</a></dt>
  442. <dd><p>Returns information about a key, as a tuple.</p>
  443. <p><em>key</em> is an already open key, or one of the predefined
  444. <a class="reference internal" href="#hkey-constants"><span class="std std-ref">HKEY_* constants</span></a>.</p>
  445. <p>The result is a tuple of 3 items:</p>
  446. <table class="docutils align-default">
  447. <thead>
  448. <tr class="row-odd"><th class="head"><p>Index</p></th>
  449. <th class="head"><p>Meaning</p></th>
  450. </tr>
  451. </thead>
  452. <tbody>
  453. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">0</span></code></p></td>
  454. <td><p>An integer giving the number of sub keys
  455. this key has.</p></td>
  456. </tr>
  457. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">1</span></code></p></td>
  458. <td><p>An integer giving the number of values this
  459. key has.</p></td>
  460. </tr>
  461. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">2</span></code></p></td>
  462. <td><p>An integer giving when the key was last
  463. modified (if available) as 100’s of
  464. nanoseconds since Jan 1, 1601.</p></td>
  465. </tr>
  466. </tbody>
  467. </table>
  468. <p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">winreg.QueryInfoKey</span></code> with argument <code class="docutils literal notranslate"><span class="pre">key</span></code>.</p>
  469. </dd></dl>
  470. <dl class="py function">
  471. <dt class="sig sig-object py" id="winreg.QueryValue">
  472. <span class="sig-prename descclassname"><span class="pre">winreg.</span></span><span class="sig-name descname"><span class="pre">QueryValue</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">key</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">sub_key</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#winreg.QueryValue" title="Link to this definition">¶</a></dt>
  473. <dd><p>Retrieves the unnamed value for a key, as a string.</p>
  474. <p><em>key</em> is an already open key, or one of the predefined
  475. <a class="reference internal" href="#hkey-constants"><span class="std std-ref">HKEY_* constants</span></a>.</p>
  476. <p><em>sub_key</em> is a string that holds the name of the subkey with which the value is
  477. associated. If this parameter is <code class="docutils literal notranslate"><span class="pre">None</span></code> or empty, the function retrieves the
  478. value set by the <a class="reference internal" href="#winreg.SetValue" title="winreg.SetValue"><code class="xref py py-func docutils literal notranslate"><span class="pre">SetValue()</span></code></a> method for the key identified by <em>key</em>.</p>
  479. <p>Values in the registry have name, type, and data components. This method
  480. retrieves the data for a key’s first value that has a <code class="docutils literal notranslate"><span class="pre">NULL</span></code> name. But the
  481. underlying API call doesn’t return the type, so always use
  482. <a class="reference internal" href="#winreg.QueryValueEx" title="winreg.QueryValueEx"><code class="xref py py-func docutils literal notranslate"><span class="pre">QueryValueEx()</span></code></a> if possible.</p>
  483. <p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">winreg.QueryValue</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">key</span></code>, <code class="docutils literal notranslate"><span class="pre">sub_key</span></code>, <code class="docutils literal notranslate"><span class="pre">value_name</span></code>.</p>
  484. </dd></dl>
  485. <dl class="py function">
  486. <dt class="sig sig-object py" id="winreg.QueryValueEx">
  487. <span class="sig-prename descclassname"><span class="pre">winreg.</span></span><span class="sig-name descname"><span class="pre">QueryValueEx</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">key</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">value_name</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#winreg.QueryValueEx" title="Link to this definition">¶</a></dt>
  488. <dd><p>Retrieves the type and data for a specified value name associated with
  489. an open registry key.</p>
  490. <p><em>key</em> is an already open key, or one of the predefined
  491. <a class="reference internal" href="#hkey-constants"><span class="std std-ref">HKEY_* constants</span></a>.</p>
  492. <p><em>value_name</em> is a string indicating the value to query.</p>
  493. <p>The result is a tuple of 2 items:</p>
  494. <table class="docutils align-default">
  495. <thead>
  496. <tr class="row-odd"><th class="head"><p>Index</p></th>
  497. <th class="head"><p>Meaning</p></th>
  498. </tr>
  499. </thead>
  500. <tbody>
  501. <tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">0</span></code></p></td>
  502. <td><p>The value of the registry item.</p></td>
  503. </tr>
  504. <tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">1</span></code></p></td>
  505. <td><p>An integer giving the registry type for
  506. this value (see table in docs for
  507. <a class="reference internal" href="#winreg.SetValueEx" title="winreg.SetValueEx"><code class="xref py py-meth docutils literal notranslate"><span class="pre">SetValueEx()</span></code></a>)</p></td>
  508. </tr>
  509. </tbody>
  510. </table>
  511. <p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">winreg.QueryValue</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">key</span></code>, <code class="docutils literal notranslate"><span class="pre">sub_key</span></code>, <code class="docutils literal notranslate"><span class="pre">value_name</span></code>.</p>
  512. </dd></dl>
  513. <dl class="py function">
  514. <dt class="sig sig-object py" id="winreg.SaveKey">
  515. <span class="sig-prename descclassname"><span class="pre">winreg.</span></span><span class="sig-name descname"><span class="pre">SaveKey</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">key</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">file_name</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#winreg.SaveKey" title="Link to this definition">¶</a></dt>
  516. <dd><p>Saves the specified key, and all its subkeys to the specified file.</p>
  517. <p><em>key</em> is an already open key, or one of the predefined
  518. <a class="reference internal" href="#hkey-constants"><span class="std std-ref">HKEY_* constants</span></a>.</p>
  519. <p><em>file_name</em> is the name of the file to save registry data to. This file
  520. cannot already exist. If this filename includes an extension, it cannot be
  521. used on file allocation table (FAT) file systems by the <a class="reference internal" href="#winreg.LoadKey" title="winreg.LoadKey"><code class="xref py py-meth docutils literal notranslate"><span class="pre">LoadKey()</span></code></a>
  522. method.</p>
  523. <p>If <em>key</em> represents a key on a remote computer, the path described by
  524. <em>file_name</em> is relative to the remote computer. The caller of this method must
  525. possess the <strong>SeBackupPrivilege</strong> security privilege. Note that
  526. privileges are different than permissions – see the
  527. <a class="reference external" href="https://msdn.microsoft.com/en-us/library/ms724878%28v=VS.85%29.aspx">Conflicts Between User Rights and Permissions documentation</a>
  528. for more details.</p>
  529. <p>This function passes <code class="docutils literal notranslate"><span class="pre">NULL</span></code> for <em>security_attributes</em> to the API.</p>
  530. <p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">winreg.SaveKey</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">key</span></code>, <code class="docutils literal notranslate"><span class="pre">file_name</span></code>.</p>
  531. </dd></dl>
  532. <dl class="py function">
  533. <dt class="sig sig-object py" id="winreg.SetValue">
  534. <span class="sig-prename descclassname"><span class="pre">winreg.</span></span><span class="sig-name descname"><span class="pre">SetValue</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">key</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">sub_key</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">type</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">value</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#winreg.SetValue" title="Link to this definition">¶</a></dt>
  535. <dd><p>Associates a value with a specified key.</p>
  536. <p><em>key</em> is an already open key, or one of the predefined
  537. <a class="reference internal" href="#hkey-constants"><span class="std std-ref">HKEY_* constants</span></a>.</p>
  538. <p><em>sub_key</em> is a string that names the subkey with which the value is associated.</p>
  539. <p><em>type</em> is an integer that specifies the type of the data. Currently this must be
  540. <a class="reference internal" href="#winreg.REG_SZ" title="winreg.REG_SZ"><code class="xref py py-const docutils literal notranslate"><span class="pre">REG_SZ</span></code></a>, meaning only strings are supported. Use the <a class="reference internal" href="#winreg.SetValueEx" title="winreg.SetValueEx"><code class="xref py py-func docutils literal notranslate"><span class="pre">SetValueEx()</span></code></a>
  541. function for support for other data types.</p>
  542. <p><em>value</em> is a string that specifies the new value.</p>
  543. <p>If the key specified by the <em>sub_key</em> parameter does not exist, the SetValue
  544. function creates it.</p>
  545. <p>Value lengths are limited by available memory. Long values (more than 2048
  546. bytes) should be stored as files with the filenames stored in the configuration
  547. registry. This helps the registry perform efficiently.</p>
  548. <p>The key identified by the <em>key</em> parameter must have been opened with
  549. <a class="reference internal" href="#winreg.KEY_SET_VALUE" title="winreg.KEY_SET_VALUE"><code class="xref py py-const docutils literal notranslate"><span class="pre">KEY_SET_VALUE</span></code></a> access.</p>
  550. <p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">winreg.SetValue</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">key</span></code>, <code class="docutils literal notranslate"><span class="pre">sub_key</span></code>, <code class="docutils literal notranslate"><span class="pre">type</span></code>, <code class="docutils literal notranslate"><span class="pre">value</span></code>.</p>
  551. </dd></dl>
  552. <dl class="py function">
  553. <dt class="sig sig-object py" id="winreg.SetValueEx">
  554. <span class="sig-prename descclassname"><span class="pre">winreg.</span></span><span class="sig-name descname"><span class="pre">SetValueEx</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">key</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">value_name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">reserved</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">type</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">value</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#winreg.SetValueEx" title="Link to this definition">¶</a></dt>
  555. <dd><p>Stores data in the value field of an open registry key.</p>
  556. <p><em>key</em> is an already open key, or one of the predefined
  557. <a class="reference internal" href="#hkey-constants"><span class="std std-ref">HKEY_* constants</span></a>.</p>
  558. <p><em>value_name</em> is a string that names the subkey with which the value is
  559. associated.</p>
  560. <p><em>reserved</em> can be anything – zero is always passed to the API.</p>
  561. <p><em>type</em> is an integer that specifies the type of the data. See
  562. <a class="reference internal" href="#value-types"><span class="std std-ref">Value Types</span></a> for the available types.</p>
  563. <p><em>value</em> is a string that specifies the new value.</p>
  564. <p>This method can also set additional value and type information for the specified
  565. key. The key identified by the key parameter must have been opened with
  566. <a class="reference internal" href="#winreg.KEY_SET_VALUE" title="winreg.KEY_SET_VALUE"><code class="xref py py-const docutils literal notranslate"><span class="pre">KEY_SET_VALUE</span></code></a> access.</p>
  567. <p>To open the key, use the <a class="reference internal" href="#winreg.CreateKey" title="winreg.CreateKey"><code class="xref py py-func docutils literal notranslate"><span class="pre">CreateKey()</span></code></a> or <a class="reference internal" href="#winreg.OpenKey" title="winreg.OpenKey"><code class="xref py py-func docutils literal notranslate"><span class="pre">OpenKey()</span></code></a> methods.</p>
  568. <p>Value lengths are limited by available memory. Long values (more than 2048
  569. bytes) should be stored as files with the filenames stored in the configuration
  570. registry. This helps the registry perform efficiently.</p>
  571. <p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">winreg.SetValue</span></code> with arguments <code class="docutils literal notranslate"><span class="pre">key</span></code>, <code class="docutils literal notranslate"><span class="pre">sub_key</span></code>, <code class="docutils literal notranslate"><span class="pre">type</span></code>, <code class="docutils literal notranslate"><span class="pre">value</span></code>.</p>
  572. </dd></dl>
  573. <dl class="py function">
  574. <dt class="sig sig-object py" id="winreg.DisableReflectionKey">
  575. <span class="sig-prename descclassname"><span class="pre">winreg.</span></span><span class="sig-name descname"><span class="pre">DisableReflectionKey</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">key</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#winreg.DisableReflectionKey" title="Link to this definition">¶</a></dt>
  576. <dd><p>Disables registry reflection for 32-bit processes running on a 64-bit
  577. operating system.</p>
  578. <p><em>key</em> is an already open key, or one of the predefined <a class="reference internal" href="#hkey-constants"><span class="std std-ref">HKEY_* constants</span></a>.</p>
  579. <p>Will generally raise <a class="reference internal" href="exceptions.html#NotImplementedError" title="NotImplementedError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NotImplementedError</span></code></a> if executed on a 32-bit operating
  580. system.</p>
  581. <p>If the key is not on the reflection list, the function succeeds but has no
  582. effect. Disabling reflection for a key does not affect reflection of any
  583. subkeys.</p>
  584. <p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">winreg.DisableReflectionKey</span></code> with argument <code class="docutils literal notranslate"><span class="pre">key</span></code>.</p>
  585. </dd></dl>
  586. <dl class="py function">
  587. <dt class="sig sig-object py" id="winreg.EnableReflectionKey">
  588. <span class="sig-prename descclassname"><span class="pre">winreg.</span></span><span class="sig-name descname"><span class="pre">EnableReflectionKey</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">key</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#winreg.EnableReflectionKey" title="Link to this definition">¶</a></dt>
  589. <dd><p>Restores registry reflection for the specified disabled key.</p>
  590. <p><em>key</em> is an already open key, or one of the predefined <a class="reference internal" href="#hkey-constants"><span class="std std-ref">HKEY_* constants</span></a>.</p>
  591. <p>Will generally raise <a class="reference internal" href="exceptions.html#NotImplementedError" title="NotImplementedError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NotImplementedError</span></code></a> if executed on a 32-bit operating
  592. system.</p>
  593. <p>Restoring reflection for a key does not affect reflection of any subkeys.</p>
  594. <p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">winreg.EnableReflectionKey</span></code> with argument <code class="docutils literal notranslate"><span class="pre">key</span></code>.</p>
  595. </dd></dl>
  596. <dl class="py function">
  597. <dt class="sig sig-object py" id="winreg.QueryReflectionKey">
  598. <span class="sig-prename descclassname"><span class="pre">winreg.</span></span><span class="sig-name descname"><span class="pre">QueryReflectionKey</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">key</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#winreg.QueryReflectionKey" title="Link to this definition">¶</a></dt>
  599. <dd><p>Determines the reflection state for the specified key.</p>
  600. <p><em>key</em> is an already open key, or one of the predefined
  601. <a class="reference internal" href="#hkey-constants"><span class="std std-ref">HKEY_* constants</span></a>.</p>
  602. <p>Returns <code class="docutils literal notranslate"><span class="pre">True</span></code> if reflection is disabled.</p>
  603. <p>Will generally raise <a class="reference internal" href="exceptions.html#NotImplementedError" title="NotImplementedError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">NotImplementedError</span></code></a> if executed on a 32-bit
  604. operating system.</p>
  605. <p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">winreg.QueryReflectionKey</span></code> with argument <code class="docutils literal notranslate"><span class="pre">key</span></code>.</p>
  606. </dd></dl>
  607. </section>
  608. <section id="constants">
  609. <span id="id2"></span><h2>Constants<a class="headerlink" href="#constants" title="Link to this heading">¶</a></h2>
  610. <p>The following constants are defined for use in many <a class="reference internal" href="#module-winreg" title="winreg: Routines and objects for manipulating the Windows registry. (Windows)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">winreg</span></code></a> functions.</p>
  611. <section id="hkey-constants">
  612. <span id="id3"></span><h3>HKEY_* Constants<a class="headerlink" href="#hkey-constants" title="Link to this heading">¶</a></h3>
  613. <dl class="py data">
  614. <dt class="sig sig-object py" id="winreg.HKEY_CLASSES_ROOT">
  615. <span class="sig-prename descclassname"><span class="pre">winreg.</span></span><span class="sig-name descname"><span class="pre">HKEY_CLASSES_ROOT</span></span><a class="headerlink" href="#winreg.HKEY_CLASSES_ROOT" title="Link to this definition">¶</a></dt>
  616. <dd><p>Registry entries subordinate to this key define types (or classes) of
  617. documents and the properties associated with those types. Shell and
  618. COM applications use the information stored under this key.</p>
  619. </dd></dl>
  620. <dl class="py data">
  621. <dt class="sig sig-object py" id="winreg.HKEY_CURRENT_USER">
  622. <span class="sig-prename descclassname"><span class="pre">winreg.</span></span><span class="sig-name descname"><span class="pre">HKEY_CURRENT_USER</span></span><a class="headerlink" href="#winreg.HKEY_CURRENT_USER" title="Link to this definition">¶</a></dt>
  623. <dd><p>Registry entries subordinate to this key define the preferences of
  624. the current user. These preferences include the settings of
  625. environment variables, data about program groups, colors, printers,
  626. network connections, and application preferences.</p>
  627. </dd></dl>
  628. <dl class="py data">
  629. <dt class="sig sig-object py" id="winreg.HKEY_LOCAL_MACHINE">
  630. <span class="sig-prename descclassname"><span class="pre">winreg.</span></span><span class="sig-name descname"><span class="pre">HKEY_LOCAL_MACHINE</span></span><a class="headerlink" href="#winreg.HKEY_LOCAL_MACHINE" title="Link to this definition">¶</a></dt>
  631. <dd><p>Registry entries subordinate to this key define the physical state
  632. of the computer, including data about the bus type, system memory,
  633. and installed hardware and software.</p>
  634. </dd></dl>
  635. <dl class="py data">
  636. <dt class="sig sig-object py" id="winreg.HKEY_USERS">
  637. <span class="sig-prename descclassname"><span class="pre">winreg.</span></span><span class="sig-name descname"><span class="pre">HKEY_USERS</span></span><a class="headerlink" href="#winreg.HKEY_USERS" title="Link to this definition">¶</a></dt>
  638. <dd><p>Registry entries subordinate to this key define the default user
  639. configuration for new users on the local computer and the user
  640. configuration for the current user.</p>
  641. </dd></dl>
  642. <dl class="py data">
  643. <dt class="sig sig-object py" id="winreg.HKEY_PERFORMANCE_DATA">
  644. <span class="sig-prename descclassname"><span class="pre">winreg.</span></span><span class="sig-name descname"><span class="pre">HKEY_PERFORMANCE_DATA</span></span><a class="headerlink" href="#winreg.HKEY_PERFORMANCE_DATA" title="Link to this definition">¶</a></dt>
  645. <dd><p>Registry entries subordinate to this key allow you to access
  646. performance data. The data is not actually stored in the registry;
  647. the registry functions cause the system to collect the data from
  648. its source.</p>
  649. </dd></dl>
  650. <dl class="py data">
  651. <dt class="sig sig-object py" id="winreg.HKEY_CURRENT_CONFIG">
  652. <span class="sig-prename descclassname"><span class="pre">winreg.</span></span><span class="sig-name descname"><span class="pre">HKEY_CURRENT_CONFIG</span></span><a class="headerlink" href="#winreg.HKEY_CURRENT_CONFIG" title="Link to this definition">¶</a></dt>
  653. <dd><p>Contains information about the current hardware profile of the
  654. local computer system.</p>
  655. </dd></dl>
  656. <dl class="py data">
  657. <dt class="sig sig-object py" id="winreg.HKEY_DYN_DATA">
  658. <span class="sig-prename descclassname"><span class="pre">winreg.</span></span><span class="sig-name descname"><span class="pre">HKEY_DYN_DATA</span></span><a class="headerlink" href="#winreg.HKEY_DYN_DATA" title="Link to this definition">¶</a></dt>
  659. <dd><p>This key is not used in versions of Windows after 98.</p>
  660. </dd></dl>
  661. </section>
  662. <section id="access-rights">
  663. <span id="id4"></span><h3>Access Rights<a class="headerlink" href="#access-rights" title="Link to this heading">¶</a></h3>
  664. <p>For more information, see <a class="reference external" href="https://msdn.microsoft.com/en-us/library/ms724878%28v=VS.85%29.aspx">Registry Key Security and Access</a>.</p>
  665. <dl class="py data">
  666. <dt class="sig sig-object py" id="winreg.KEY_ALL_ACCESS">
  667. <span class="sig-prename descclassname"><span class="pre">winreg.</span></span><span class="sig-name descname"><span class="pre">KEY_ALL_ACCESS</span></span><a class="headerlink" href="#winreg.KEY_ALL_ACCESS" title="Link to this definition">¶</a></dt>
  668. <dd><p>Combines the STANDARD_RIGHTS_REQUIRED, <a class="reference internal" href="#winreg.KEY_QUERY_VALUE" title="winreg.KEY_QUERY_VALUE"><code class="xref py py-const docutils literal notranslate"><span class="pre">KEY_QUERY_VALUE</span></code></a>,
  669. <a class="reference internal" href="#winreg.KEY_SET_VALUE" title="winreg.KEY_SET_VALUE"><code class="xref py py-const docutils literal notranslate"><span class="pre">KEY_SET_VALUE</span></code></a>, <a class="reference internal" href="#winreg.KEY_CREATE_SUB_KEY" title="winreg.KEY_CREATE_SUB_KEY"><code class="xref py py-const docutils literal notranslate"><span class="pre">KEY_CREATE_SUB_KEY</span></code></a>,
  670. <a class="reference internal" href="#winreg.KEY_ENUMERATE_SUB_KEYS" title="winreg.KEY_ENUMERATE_SUB_KEYS"><code class="xref py py-const docutils literal notranslate"><span class="pre">KEY_ENUMERATE_SUB_KEYS</span></code></a>, <a class="reference internal" href="#winreg.KEY_NOTIFY" title="winreg.KEY_NOTIFY"><code class="xref py py-const docutils literal notranslate"><span class="pre">KEY_NOTIFY</span></code></a>,
  671. and <a class="reference internal" href="#winreg.KEY_CREATE_LINK" title="winreg.KEY_CREATE_LINK"><code class="xref py py-const docutils literal notranslate"><span class="pre">KEY_CREATE_LINK</span></code></a> access rights.</p>
  672. </dd></dl>
  673. <dl class="py data">
  674. <dt class="sig sig-object py" id="winreg.KEY_WRITE">
  675. <span class="sig-prename descclassname"><span class="pre">winreg.</span></span><span class="sig-name descname"><span class="pre">KEY_WRITE</span></span><a class="headerlink" href="#winreg.KEY_WRITE" title="Link to this definition">¶</a></dt>
  676. <dd><p>Combines the STANDARD_RIGHTS_WRITE, <a class="reference internal" href="#winreg.KEY_SET_VALUE" title="winreg.KEY_SET_VALUE"><code class="xref py py-const docutils literal notranslate"><span class="pre">KEY_SET_VALUE</span></code></a>, and
  677. <a class="reference internal" href="#winreg.KEY_CREATE_SUB_KEY" title="winreg.KEY_CREATE_SUB_KEY"><code class="xref py py-const docutils literal notranslate"><span class="pre">KEY_CREATE_SUB_KEY</span></code></a> access rights.</p>
  678. </dd></dl>
  679. <dl class="py data">
  680. <dt class="sig sig-object py" id="winreg.KEY_READ">
  681. <span class="sig-prename descclassname"><span class="pre">winreg.</span></span><span class="sig-name descname"><span class="pre">KEY_READ</span></span><a class="headerlink" href="#winreg.KEY_READ" title="Link to this definition">¶</a></dt>
  682. <dd><p>Combines the STANDARD_RIGHTS_READ, <a class="reference internal" href="#winreg.KEY_QUERY_VALUE" title="winreg.KEY_QUERY_VALUE"><code class="xref py py-const docutils literal notranslate"><span class="pre">KEY_QUERY_VALUE</span></code></a>,
  683. <a class="reference internal" href="#winreg.KEY_ENUMERATE_SUB_KEYS" title="winreg.KEY_ENUMERATE_SUB_KEYS"><code class="xref py py-const docutils literal notranslate"><span class="pre">KEY_ENUMERATE_SUB_KEYS</span></code></a>, and <a class="reference internal" href="#winreg.KEY_NOTIFY" title="winreg.KEY_NOTIFY"><code class="xref py py-const docutils literal notranslate"><span class="pre">KEY_NOTIFY</span></code></a> values.</p>
  684. </dd></dl>
  685. <dl class="py data">
  686. <dt class="sig sig-object py" id="winreg.KEY_EXECUTE">
  687. <span class="sig-prename descclassname"><span class="pre">winreg.</span></span><span class="sig-name descname"><span class="pre">KEY_EXECUTE</span></span><a class="headerlink" href="#winreg.KEY_EXECUTE" title="Link to this definition">¶</a></dt>
  688. <dd><p>Equivalent to <a class="reference internal" href="#winreg.KEY_READ" title="winreg.KEY_READ"><code class="xref py py-const docutils literal notranslate"><span class="pre">KEY_READ</span></code></a>.</p>
  689. </dd></dl>
  690. <dl class="py data">
  691. <dt class="sig sig-object py" id="winreg.KEY_QUERY_VALUE">
  692. <span class="sig-prename descclassname"><span class="pre">winreg.</span></span><span class="sig-name descname"><span class="pre">KEY_QUERY_VALUE</span></span><a class="headerlink" href="#winreg.KEY_QUERY_VALUE" title="Link to this definition">¶</a></dt>
  693. <dd><p>Required to query the values of a registry key.</p>
  694. </dd></dl>
  695. <dl class="py data">
  696. <dt class="sig sig-object py" id="winreg.KEY_SET_VALUE">
  697. <span class="sig-prename descclassname"><span class="pre">winreg.</span></span><span class="sig-name descname"><span class="pre">KEY_SET_VALUE</span></span><a class="headerlink" href="#winreg.KEY_SET_VALUE" title="Link to this definition">¶</a></dt>
  698. <dd><p>Required to create, delete, or set a registry value.</p>
  699. </dd></dl>
  700. <dl class="py data">
  701. <dt class="sig sig-object py" id="winreg.KEY_CREATE_SUB_KEY">
  702. <span class="sig-prename descclassname"><span class="pre">winreg.</span></span><span class="sig-name descname"><span class="pre">KEY_CREATE_SUB_KEY</span></span><a class="headerlink" href="#winreg.KEY_CREATE_SUB_KEY" title="Link to this definition">¶</a></dt>
  703. <dd><p>Required to create a subkey of a registry key.</p>
  704. </dd></dl>
  705. <dl class="py data">
  706. <dt class="sig sig-object py" id="winreg.KEY_ENUMERATE_SUB_KEYS">
  707. <span class="sig-prename descclassname"><span class="pre">winreg.</span></span><span class="sig-name descname"><span class="pre">KEY_ENUMERATE_SUB_KEYS</span></span><a class="headerlink" href="#winreg.KEY_ENUMERATE_SUB_KEYS" title="Link to this definition">¶</a></dt>
  708. <dd><p>Required to enumerate the subkeys of a registry key.</p>
  709. </dd></dl>
  710. <dl class="py data">
  711. <dt class="sig sig-object py" id="winreg.KEY_NOTIFY">
  712. <span class="sig-prename descclassname"><span class="pre">winreg.</span></span><span class="sig-name descname"><span class="pre">KEY_NOTIFY</span></span><a class="headerlink" href="#winreg.KEY_NOTIFY" title="Link to this definition">¶</a></dt>
  713. <dd><p>Required to request change notifications for a registry key or for
  714. subkeys of a registry key.</p>
  715. </dd></dl>
  716. <dl class="py data">
  717. <dt class="sig sig-object py" id="winreg.KEY_CREATE_LINK">
  718. <span class="sig-prename descclassname"><span class="pre">winreg.</span></span><span class="sig-name descname"><span class="pre">KEY_CREATE_LINK</span></span><a class="headerlink" href="#winreg.KEY_CREATE_LINK" title="Link to this definition">¶</a></dt>
  719. <dd><p>Reserved for system use.</p>
  720. </dd></dl>
  721. <section id="bit-specific">
  722. <span id="bit-access-rights"></span><h4>64-bit Specific<a class="headerlink" href="#bit-specific" title="Link to this heading">¶</a></h4>
  723. <p>For more information, see <a class="reference external" href="https://msdn.microsoft.com/en-us/library/aa384129(v=VS.85).aspx">Accessing an Alternate Registry View</a>.</p>
  724. <dl class="py data">
  725. <dt class="sig sig-object py" id="winreg.KEY_WOW64_64KEY">
  726. <span class="sig-prename descclassname"><span class="pre">winreg.</span></span><span class="sig-name descname"><span class="pre">KEY_WOW64_64KEY</span></span><a class="headerlink" href="#winreg.KEY_WOW64_64KEY" title="Link to this definition">¶</a></dt>
  727. <dd><p>Indicates that an application on 64-bit Windows should operate on
  728. the 64-bit registry view. On 32-bit Windows, this constant is ignored.</p>
  729. </dd></dl>
  730. <dl class="py data">
  731. <dt class="sig sig-object py" id="winreg.KEY_WOW64_32KEY">
  732. <span class="sig-prename descclassname"><span class="pre">winreg.</span></span><span class="sig-name descname"><span class="pre">KEY_WOW64_32KEY</span></span><a class="headerlink" href="#winreg.KEY_WOW64_32KEY" title="Link to this definition">¶</a></dt>
  733. <dd><p>Indicates that an application on 64-bit Windows should operate on
  734. the 32-bit registry view. On 32-bit Windows, this constant is ignored.</p>
  735. </dd></dl>
  736. </section>
  737. </section>
  738. <section id="value-types">
  739. <span id="id5"></span><h3>Value Types<a class="headerlink" href="#value-types" title="Link to this heading">¶</a></h3>
  740. <p>For more information, see <a class="reference external" href="https://msdn.microsoft.com/en-us/library/ms724884%28v=VS.85%29.aspx">Registry Value Types</a>.</p>
  741. <dl class="py data">
  742. <dt class="sig sig-object py" id="winreg.REG_BINARY">
  743. <span class="sig-prename descclassname"><span class="pre">winreg.</span></span><span class="sig-name descname"><span class="pre">REG_BINARY</span></span><a class="headerlink" href="#winreg.REG_BINARY" title="Link to this definition">¶</a></dt>
  744. <dd><p>Binary data in any form.</p>
  745. </dd></dl>
  746. <dl class="py data">
  747. <dt class="sig sig-object py" id="winreg.REG_DWORD">
  748. <span class="sig-prename descclassname"><span class="pre">winreg.</span></span><span class="sig-name descname"><span class="pre">REG_DWORD</span></span><a class="headerlink" href="#winreg.REG_DWORD" title="Link to this definition">¶</a></dt>
  749. <dd><p>32-bit number.</p>
  750. </dd></dl>
  751. <dl class="py data">
  752. <dt class="sig sig-object py" id="winreg.REG_DWORD_LITTLE_ENDIAN">
  753. <span class="sig-prename descclassname"><span class="pre">winreg.</span></span><span class="sig-name descname"><span class="pre">REG_DWORD_LITTLE_ENDIAN</span></span><a class="headerlink" href="#winreg.REG_DWORD_LITTLE_ENDIAN" title="Link to this definition">¶</a></dt>
  754. <dd><p>A 32-bit number in little-endian format. Equivalent to <a class="reference internal" href="#winreg.REG_DWORD" title="winreg.REG_DWORD"><code class="xref py py-const docutils literal notranslate"><span class="pre">REG_DWORD</span></code></a>.</p>
  755. </dd></dl>
  756. <dl class="py data">
  757. <dt class="sig sig-object py" id="winreg.REG_DWORD_BIG_ENDIAN">
  758. <span class="sig-prename descclassname"><span class="pre">winreg.</span></span><span class="sig-name descname"><span class="pre">REG_DWORD_BIG_ENDIAN</span></span><a class="headerlink" href="#winreg.REG_DWORD_BIG_ENDIAN" title="Link to this definition">¶</a></dt>
  759. <dd><p>A 32-bit number in big-endian format.</p>
  760. </dd></dl>
  761. <dl class="py data">
  762. <dt class="sig sig-object py" id="winreg.REG_EXPAND_SZ">
  763. <span class="sig-prename descclassname"><span class="pre">winreg.</span></span><span class="sig-name descname"><span class="pre">REG_EXPAND_SZ</span></span><a class="headerlink" href="#winreg.REG_EXPAND_SZ" title="Link to this definition">¶</a></dt>
  764. <dd><p>Null-terminated string containing references to environment
  765. variables (<code class="docutils literal notranslate"><span class="pre">%PATH%</span></code>).</p>
  766. </dd></dl>
  767. <dl class="py data">
  768. <dt class="sig sig-object py" id="winreg.REG_LINK">
  769. <span class="sig-prename descclassname"><span class="pre">winreg.</span></span><span class="sig-name descname"><span class="pre">REG_LINK</span></span><a class="headerlink" href="#winreg.REG_LINK" title="Link to this definition">¶</a></dt>
  770. <dd><p>A Unicode symbolic link.</p>
  771. </dd></dl>
  772. <dl class="py data">
  773. <dt class="sig sig-object py" id="winreg.REG_MULTI_SZ">
  774. <span class="sig-prename descclassname"><span class="pre">winreg.</span></span><span class="sig-name descname"><span class="pre">REG_MULTI_SZ</span></span><a class="headerlink" href="#winreg.REG_MULTI_SZ" title="Link to this definition">¶</a></dt>
  775. <dd><p>A sequence of null-terminated strings, terminated by two null characters.
  776. (Python handles this termination automatically.)</p>
  777. </dd></dl>
  778. <dl class="py data">
  779. <dt class="sig sig-object py" id="winreg.REG_NONE">
  780. <span class="sig-prename descclassname"><span class="pre">winreg.</span></span><span class="sig-name descname"><span class="pre">REG_NONE</span></span><a class="headerlink" href="#winreg.REG_NONE" title="Link to this definition">¶</a></dt>
  781. <dd><p>No defined value type.</p>
  782. </dd></dl>
  783. <dl class="py data">
  784. <dt class="sig sig-object py" id="winreg.REG_QWORD">
  785. <span class="sig-prename descclassname"><span class="pre">winreg.</span></span><span class="sig-name descname"><span class="pre">REG_QWORD</span></span><a class="headerlink" href="#winreg.REG_QWORD" title="Link to this definition">¶</a></dt>
  786. <dd><p>A 64-bit number.</p>
  787. <div class="versionadded">
  788. <p><span class="versionmodified added">New in version 3.6.</span></p>
  789. </div>
  790. </dd></dl>
  791. <dl class="py data">
  792. <dt class="sig sig-object py" id="winreg.REG_QWORD_LITTLE_ENDIAN">
  793. <span class="sig-prename descclassname"><span class="pre">winreg.</span></span><span class="sig-name descname"><span class="pre">REG_QWORD_LITTLE_ENDIAN</span></span><a class="headerlink" href="#winreg.REG_QWORD_LITTLE_ENDIAN" title="Link to this definition">¶</a></dt>
  794. <dd><p>A 64-bit number in little-endian format. Equivalent to <a class="reference internal" href="#winreg.REG_QWORD" title="winreg.REG_QWORD"><code class="xref py py-const docutils literal notranslate"><span class="pre">REG_QWORD</span></code></a>.</p>
  795. <div class="versionadded">
  796. <p><span class="versionmodified added">New in version 3.6.</span></p>
  797. </div>
  798. </dd></dl>
  799. <dl class="py data">
  800. <dt class="sig sig-object py" id="winreg.REG_RESOURCE_LIST">
  801. <span class="sig-prename descclassname"><span class="pre">winreg.</span></span><span class="sig-name descname"><span class="pre">REG_RESOURCE_LIST</span></span><a class="headerlink" href="#winreg.REG_RESOURCE_LIST" title="Link to this definition">¶</a></dt>
  802. <dd><p>A device-driver resource list.</p>
  803. </dd></dl>
  804. <dl class="py data">
  805. <dt class="sig sig-object py" id="winreg.REG_FULL_RESOURCE_DESCRIPTOR">
  806. <span class="sig-prename descclassname"><span class="pre">winreg.</span></span><span class="sig-name descname"><span class="pre">REG_FULL_RESOURCE_DESCRIPTOR</span></span><a class="headerlink" href="#winreg.REG_FULL_RESOURCE_DESCRIPTOR" title="Link to this definition">¶</a></dt>
  807. <dd><p>A hardware setting.</p>
  808. </dd></dl>
  809. <dl class="py data">
  810. <dt class="sig sig-object py" id="winreg.REG_RESOURCE_REQUIREMENTS_LIST">
  811. <span class="sig-prename descclassname"><span class="pre">winreg.</span></span><span class="sig-name descname"><span class="pre">REG_RESOURCE_REQUIREMENTS_LIST</span></span><a class="headerlink" href="#winreg.REG_RESOURCE_REQUIREMENTS_LIST" title="Link to this definition">¶</a></dt>
  812. <dd><p>A hardware resource list.</p>
  813. </dd></dl>
  814. <dl class="py data">
  815. <dt class="sig sig-object py" id="winreg.REG_SZ">
  816. <span class="sig-prename descclassname"><span class="pre">winreg.</span></span><span class="sig-name descname"><span class="pre">REG_SZ</span></span><a class="headerlink" href="#winreg.REG_SZ" title="Link to this definition">¶</a></dt>
  817. <dd><p>A null-terminated string.</p>
  818. </dd></dl>
  819. </section>
  820. </section>
  821. <section id="registry-handle-objects">
  822. <span id="handle-object"></span><h2>Registry Handle Objects<a class="headerlink" href="#registry-handle-objects" title="Link to this heading">¶</a></h2>
  823. <p>This object wraps a Windows HKEY object, automatically closing it when the
  824. object is destroyed. To guarantee cleanup, you can call either the
  825. <a class="reference internal" href="#winreg.PyHKEY.Close" title="winreg.PyHKEY.Close"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Close()</span></code></a> method on the object, or the <a class="reference internal" href="#winreg.CloseKey" title="winreg.CloseKey"><code class="xref py py-func docutils literal notranslate"><span class="pre">CloseKey()</span></code></a> function.</p>
  826. <p>All registry functions in this module return one of these objects.</p>
  827. <p>All registry functions in this module which accept a handle object also accept
  828. an integer, however, use of the handle object is encouraged.</p>
  829. <p>Handle objects provide semantics for <a class="reference internal" href="../reference/datamodel.html#object.__bool__" title="object.__bool__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__bool__()</span></code></a> – thus</p>
  830. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">if</span> <span class="n">handle</span><span class="p">:</span>
  831. <span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Yes&quot;</span><span class="p">)</span>
  832. </pre></div>
  833. </div>
  834. <p>will print <code class="docutils literal notranslate"><span class="pre">Yes</span></code> if the handle is currently valid (has not been closed or
  835. detached).</p>
  836. <p>The object also support comparison semantics, so handle objects will compare
  837. true if they both reference the same underlying Windows handle value.</p>
  838. <p>Handle objects can be converted to an integer (e.g., using the built-in
  839. <a class="reference internal" href="functions.html#int" title="int"><code class="xref py py-func docutils literal notranslate"><span class="pre">int()</span></code></a> function), in which case the underlying Windows handle value is
  840. returned. You can also use the <a class="reference internal" href="#winreg.PyHKEY.Detach" title="winreg.PyHKEY.Detach"><code class="xref py py-meth docutils literal notranslate"><span class="pre">Detach()</span></code></a> method to return the
  841. integer handle, and also disconnect the Windows handle from the handle object.</p>
  842. <dl class="py method">
  843. <dt class="sig sig-object py" id="winreg.PyHKEY.Close">
  844. <span class="sig-prename descclassname"><span class="pre">PyHKEY.</span></span><span class="sig-name descname"><span class="pre">Close</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#winreg.PyHKEY.Close" title="Link to this definition">¶</a></dt>
  845. <dd><p>Closes the underlying Windows handle.</p>
  846. <p>If the handle is already closed, no error is raised.</p>
  847. </dd></dl>
  848. <dl class="py method">
  849. <dt class="sig sig-object py" id="winreg.PyHKEY.Detach">
  850. <span class="sig-prename descclassname"><span class="pre">PyHKEY.</span></span><span class="sig-name descname"><span class="pre">Detach</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#winreg.PyHKEY.Detach" title="Link to this definition">¶</a></dt>
  851. <dd><p>Detaches the Windows handle from the handle object.</p>
  852. <p>The result is an integer that holds the value of the handle before it is
  853. detached. If the handle is already detached or closed, this will return
  854. zero.</p>
  855. <p>After calling this function, the handle is effectively invalidated, but the
  856. handle is not closed. You would call this function when you need the
  857. underlying Win32 handle to exist beyond the lifetime of the handle object.</p>
  858. <p class="audit-hook">Raises an <a class="reference internal" href="sys.html#auditing"><span class="std std-ref">auditing event</span></a> <code class="docutils literal notranslate"><span class="pre">winreg.PyHKEY.Detach</span></code> with argument <code class="docutils literal notranslate"><span class="pre">key</span></code>.</p>
  859. </dd></dl>
  860. <dl class="py method">
  861. <dt class="sig sig-object py" id="winreg.PyHKEY.__enter__">
  862. <span class="sig-prename descclassname"><span class="pre">PyHKEY.</span></span><span class="sig-name descname"><span class="pre">__enter__</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#winreg.PyHKEY.__enter__" title="Link to this definition">¶</a></dt>
  863. <dt class="sig sig-object py" id="winreg.PyHKEY.__exit__">
  864. <span class="sig-prename descclassname"><span class="pre">PyHKEY.</span></span><span class="sig-name descname"><span class="pre">__exit__</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="o"><span class="pre">*</span></span><span class="n"><span class="pre">exc_info</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#winreg.PyHKEY.__exit__" title="Link to this definition">¶</a></dt>
  865. <dd><p>The HKEY object implements <a class="reference internal" href="../reference/datamodel.html#object.__enter__" title="object.__enter__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__enter__()</span></code></a> and
  866. <a class="reference internal" href="../reference/datamodel.html#object.__exit__" title="object.__exit__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__exit__()</span></code></a> and thus supports the context protocol for the
  867. <a class="reference internal" href="../reference/compound_stmts.html#with"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">with</span></code></a> statement:</p>
  868. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">with</span> <span class="n">OpenKey</span><span class="p">(</span><span class="n">HKEY_LOCAL_MACHINE</span><span class="p">,</span> <span class="s2">&quot;foo&quot;</span><span class="p">)</span> <span class="k">as</span> <span class="n">key</span><span class="p">:</span>
  869. <span class="o">...</span> <span class="c1"># work with key</span>
  870. </pre></div>
  871. </div>
  872. <p>will automatically close <em>key</em> when control leaves the <a class="reference internal" href="../reference/compound_stmts.html#with"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">with</span></code></a> block.</p>
  873. </dd></dl>
  874. </section>
  875. </section>
  876. <div class="clearer"></div>
  877. </div>
  878. </div>
  879. </div>
  880. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  881. <div class="sphinxsidebarwrapper">
  882. <div>
  883. <h3><a href="../contents.html">Table of Contents</a></h3>
  884. <ul>
  885. <li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">winreg</span></code> — Windows registry access</a><ul>
  886. <li><a class="reference internal" href="#functions">Functions</a></li>
  887. <li><a class="reference internal" href="#constants">Constants</a><ul>
  888. <li><a class="reference internal" href="#hkey-constants">HKEY_* Constants</a></li>
  889. <li><a class="reference internal" href="#access-rights">Access Rights</a><ul>
  890. <li><a class="reference internal" href="#bit-specific">64-bit Specific</a></li>
  891. </ul>
  892. </li>
  893. <li><a class="reference internal" href="#value-types">Value Types</a></li>
  894. </ul>
  895. </li>
  896. <li><a class="reference internal" href="#registry-handle-objects">Registry Handle Objects</a></li>
  897. </ul>
  898. </li>
  899. </ul>
  900. </div>
  901. <div>
  902. <h4>Previous topic</h4>
  903. <p class="topless"><a href="msvcrt.html"
  904. title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">msvcrt</span></code> — Useful routines from the MS VC++ runtime</a></p>
  905. </div>
  906. <div>
  907. <h4>Next topic</h4>
  908. <p class="topless"><a href="winsound.html"
  909. title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">winsound</span></code> — Sound-playing interface for Windows</a></p>
  910. </div>
  911. <div role="note" aria-label="source link">
  912. <h3>This Page</h3>
  913. <ul class="this-page-menu">
  914. <li><a href="../bugs.html">Report a Bug</a></li>
  915. <li>
  916. <a href="https://github.com/python/cpython/blob/main/Doc/library/winreg.rst"
  917. rel="nofollow">Show Source
  918. </a>
  919. </li>
  920. </ul>
  921. </div>
  922. </div>
  923. <div id="sidebarbutton" title="Collapse sidebar">
  924. <span>«</span>
  925. </div>
  926. </div>
  927. <div class="clearer"></div>
  928. </div>
  929. <div class="related" role="navigation" aria-label="related navigation">
  930. <h3>Navigation</h3>
  931. <ul>
  932. <li class="right" style="margin-right: 10px">
  933. <a href="../genindex.html" title="General Index"
  934. >index</a></li>
  935. <li class="right" >
  936. <a href="../py-modindex.html" title="Python Module Index"
  937. >modules</a> |</li>
  938. <li class="right" >
  939. <a href="winsound.html" title="winsound — Sound-playing interface for Windows"
  940. >next</a> |</li>
  941. <li class="right" >
  942. <a href="msvcrt.html" title="msvcrt — Useful routines from the MS VC++ runtime"
  943. >previous</a> |</li>
  944. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  945. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  946. <li class="switchers">
  947. <div class="language_switcher_placeholder"></div>
  948. <div class="version_switcher_placeholder"></div>
  949. </li>
  950. <li>
  951. </li>
  952. <li id="cpython-language-and-version">
  953. <a href="../index.html">3.12.3 Documentation</a> &#187;
  954. </li>
  955. <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
  956. <li class="nav-item nav-item-2"><a href="windows.html" >MS Windows Specific Services</a> &#187;</li>
  957. <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">winreg</span></code> — Windows registry access</a></li>
  958. <li class="right">
  959. <div class="inline-search" role="search">
  960. <form class="inline-search" action="../search.html" method="get">
  961. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  962. <input type="submit" value="Go" />
  963. </form>
  964. </div>
  965. |
  966. </li>
  967. <li class="right">
  968. <label class="theme-selector-label">
  969. Theme
  970. <select class="theme-selector" oninput="activateTheme(this.value)">
  971. <option value="auto" selected>Auto</option>
  972. <option value="light">Light</option>
  973. <option value="dark">Dark</option>
  974. </select>
  975. </label> |</li>
  976. </ul>
  977. </div>
  978. <div class="footer">
  979. &copy;
  980. <a href="../copyright.html">
  981. Copyright
  982. </a>
  983. 2001-2024, Python Software Foundation.
  984. <br />
  985. This page is licensed under the Python Software Foundation License Version 2.
  986. <br />
  987. Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
  988. <br />
  989. See <a href="/license.html">History and License</a> for more information.<br />
  990. <br />
  991. The Python Software Foundation is a non-profit corporation.
  992. <a href="https://www.python.org/psf/donations/">Please donate.</a>
  993. <br />
  994. <br />
  995. Last updated on Apr 09, 2024 (13:47 UTC).
  996. <a href="/bugs.html">Found a bug</a>?
  997. <br />
  998. Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.2.6.
  999. </div>
  1000. </body>
  1001. </html>
上海开阖软件有限公司 沪ICP备12045867号-1