Classes¶
FILETIME¶
- wslwinreg.common.FILETIME : public Structure
Structure to mimic the Windows FILETIME data type.
- Parameters
None –
WindowsError¶
- wslwinreg.cygwinapi.WindowsError : public OSError
This exception doesn’t exist in Cygwin/MSYS, provide it.
Public Functions
- __init__(self, winerror, strerror=None, filename=None)¶
Initialize a WindowsError exception.
- Parameters
winerror – The windows error code
strerror – The string describing the error
filename – Name of the file that caused this error, if applicable.
- __str__(self)¶
Convert the class into a string.
- Returns
String describing the error contained.
PyHKEY¶
- class PyHKEY¶
A Python object representing a win32 registry key.
This object wraps a Windows HKEY object, automatically closing it when the object is destroyed. To guarantee cleanup, you can call either the Close() method on the object, or the CloseKey() function.
All registry functions in this module return one of these objects.
All registry functions in this module which accept a handle object also accept an integer, however, use of the handle object is encouraged.
Handle objects provide semantics for bool() – thus
if handle: print("Yes")
will print Yes if the handle is currently valid (has not been closed or detached).
The object also support comparison semantics, so handle objects will compare true if they both reference the same underlying Windows handle value.
Handle objects can be converted to an integer (e.g., using the built-in int() function), in which case the underlying Windows handle value is returned. You can also use the Detach() method to return the integer handle, and also disconnect the Windows handle from the handle object.
Public Functions
- __init__(self, hkey, null_ok=False)¶
Initialize the PyHKEY class.
- Parameters
hkey – Integer value representing the pointer to the HKEY
null_ok – True if None is acceptable.
- __del__(self)¶
Called when this object is garbage collected.
- Close(self)¶
Closes the underlying Windows handle.
Note
If the handle is already closed, no error is raised.
- Detach(self)¶
Detaches the Windows handle from the handle object.
After calling this function, the handle is effectively invalidated, but the handle is not closed. You would call this function when you need the underlying win32 handle to exist beyond the lifetime of the handle object.
On 64 bit windows, the result of this function is a long integer.
Note
The result is the value of the handle before it is detached. If the handle is already detached, this will return zero.
- Returns
Previous HKEY integer.
- __enter__(self)¶
Called when object is entered.
Note
Needed for the Python
with
statement.
- __exit__(self, exc_type, exc_value, exc_traceback)¶
Release handle on class destruction.
Note
Needed for the Python
with
statement.
- __hash__(self)¶
Convert the object into a hash.
Note
The implementation returns the id, which should be random enough.
- __int__(self)¶
Converting a handle to an integer returns the Win32 handle.
- __nonzero__(self)¶
Handles with an open object return true, otherwise false.
- __bool__(self)¶
Handles with an open object return true, otherwise false.
- __repr__(self)¶
Return descriptive string for the class object.
- __str__(self)¶
Return short string for the handle object.
Public Members
- hkey¶
Integer that represents the HANDLE pointer.
WinRegKey¶
- class WinRegKey¶
Registry key helper class.
Manage entries in a registy key by using indexing and scanning.
Public Functions
- __init__(self, root_key, subkey, access)¶
Initialize the class.
- Parameters
root_key – Root key enumeration
subkey – String or None for name of sub key
access – Access flags to pass to OpenKeyEx()
- __enter__(self)¶
Enable enter/exit functionality.
- __exit__(self, exception_type, exception_value, traceback)¶
Release resources on class release.
- Parameters
exception_type – Ignored
exception_value – Ignored
traceback – Ignored
- close(self)¶
Release existing key, if any.
- open_subkey(self, subkey, access=None)¶
Open a sub key.
- Parameters
subkey – Name of the subkey to open
access – Desired access to the subkey.
- Returns
An instance of the WinRegKey of the new key.
- get_subkeys(self)¶
Return the list of all of the sub key names.
Iterate over all of the sub keys and place their names in a list. Return the list. Unicode is properly handled.
- Returns
list of names of all the subkeys.
- get_value(self, value_name=None)¶
Read a value from a registry key.
Note
If the type returned is REG_SZ, scan for a null and trucate. If the type returned is REG_EXPAND_SZ, call
ExpandEnvironmentStrings()
- Parameters
value_name – String of the name of the value, None for default.
- Returns
Value returned from QueryValueEx()
- get_all_values(self)¶
Return a dict of all key name and associated values.
- Returns
dict with each item is the returned value from QueryValueEx()
- __getitem__(self, subkey)¶
Call open_subkey() with subscript.
Uses the access flags from this key to open the sub key.
- Parameters
subkey – Requested sub key.
- Returns
An instance of the WinRegKey of the new key.
- __iter__(self)¶
Iterator of the sub keys.
Call get_subkeys() and encapsulate the value in an iter()
- Returns
iter of get_subkeys()