winreg --- Windows 註冊表存取¶
These functions expose the Windows registry API to Python. Instead of using an integer as the registry handle, a handle object is used to ensure that the handles are closed correctly, even if the programmer neglects to explicitly close them.
可用性: Windows.
在 3.3 版的變更: Several functions in this module used to raise a
WindowsError, which is now an alias of OSError.
函式¶
This module offers the following functions:
- winreg.CloseKey(hkey)¶
Closes a previously opened registry key. The hkey argument specifies a previously opened key.
備註
If hkey is not closed using this method (or via
hkey.Close()), it is closed when the hkey object is destroyed by Python.
- winreg.ConnectRegistry(computer_name, key)¶
Establishes a connection to a predefined registry handle on another computer, and returns a handle object.
computer_name is the name of the remote computer, of the form
r"\\computername". IfNone, the local computer is used.key is the predefined handle to connect to.
The return value is the handle of the opened key. If the function fails, an
OSErrorexception is raised.引發一個附帶引數
computer_name、key的稽核事件winreg.ConnectRegistry。在 3.3 版的變更: See above.
- winreg.CreateKey(key, sub_key)¶
Creates or opens the specified key, returning a handle object.
key is an already open key, or one of the predefined HKEY_* constants.
sub_key is a string that names the key this method opens or creates.
If key is one of the predefined keys, sub_key may be
None. In that case, the handle returned is the same key handle passed in to the function.If the key already exists, this function opens the existing key.
The return value is the handle of the opened key. If the function fails, an
OSErrorexception is raised.引發一個附帶引數
key、sub_key、access的稽核事件winreg.CreateKey。引發一個附帶引數
key的稽核事件winreg.OpenKey/result。在 3.3 版的變更: See above.
- winreg.CreateKeyEx(key, sub_key, reserved=0, access=KEY_WRITE)¶
Creates or opens the specified key, returning a handle object.
key is an already open key, or one of the predefined HKEY_* constants.
sub_key is a string that names the key this method opens or creates.
reserved is a reserved integer, and must be zero. The default is zero.
access is an integer that specifies an access mask that describes the desired security access for the key. Default is
KEY_WRITE. See Access Rights for other allowed values.If key is one of the predefined keys, sub_key may be
None. In that case, the handle returned is the same key handle passed in to the function.If the key already exists, this function opens the existing key.
The return value is the handle of the opened key. If the function fails, an
OSErrorexception is raised.引發一個附帶引數
key、sub_key、access的稽核事件winreg.CreateKey。引發一個附帶引數
key的稽核事件winreg.OpenKey/result。在 3.2 版被加入.
在 3.3 版的變更: See above.
- winreg.DeleteKey(key, sub_key)¶
Deletes the specified key.
key is an already open key, or one of the predefined HKEY_* constants.
sub_key is a string that must be a subkey of the key identified by the key parameter. This value must not be
None, and the key may not have subkeys.This method can not delete keys with subkeys.
If the method succeeds, the entire key, including all of its values, is removed. If the method fails, an
OSErrorexception is raised.引發一個附帶引數
key、sub_key、access的稽核事件