|
wslwinreg
|
Package that implements winreg for Windows Subsystem for Linux. More...
Classes | |
| class | Commands |
| Commands to send to the bridging executable. More... | |
| class | FileNotFoundError |
| pypy2 does not define this exception More... | |
| class | PyHKEY |
| A Python object representing a win32 registry key. More... | |
| class | WindowsError |
| This exception doesn't exist in Cygwin/MSYS, provide it. More... | |
Functions | |
| test_string (input_string) | |
| Raise an exception if the input is not None or a string. | |
| convert_to_windows_path (path_name) | |
| Convert a WSL path to windows if needed. | |
| convert_from_windows_path (path_name) | |
| Convert an absolute Windows path to WSL. | |
| find_windows_boot_drive () | |
| Using the PATH, determine the boot drive. | |
| get_windows_user () | |
| Determine the name of the user logged into Windows. | |
| get_exe_path () | |
| Determine where the bridge exe resides. | |
| handleLRESULT () | |
| Receive the LRESULT from the bridge. | |
| create_string_buffer (temp_string, is_binary=False) | |
| Convert a string into a utf-8 byte stream. | |
| recv_string (convert_to_string=True) | |
| Recieve a string from the socket. | |
| _RegCloseKey (hkey) | |
| Low level function to call RegCloseKey. | |
| CloseKey (hkey) | |
| Closes a previously opened registry key. | |
| ConnectRegistry (computer_name, key) | |
| Establishes a connection to a predefined registry handle. | |
| CreateKey (key, sub_key) | |
| Creates or opens the specified key. | |
| CreateKeyEx (key, sub_key, reserved=0, access=KEY_WRITE) | |
| Creates or opens the specified key. | |
| DeleteKey (key, sub_key) | |
| Not implemented. | |
| DeleteKeyEx (key, sub_key, access=KEY_WOW64_64KEY, reserved=0) | |
| Deletes the specified key. | |
| DeleteValue (key, value) | |
| Removes a named value from a registry key. | |
| EnumKey (key, index) | |
| Enumerates subkeys of an open registry key, returning a string. | |
| EnumValue (key, index) | |
| Enumerates values of an open registry key, returning a tuple. | |
| ExpandEnvironmentStrings (str) | |
| Expands environment variables. | |
| FlushKey (key) | |
| Writes all the attributes of a key to the registry. | |
| LoadKey (key, sub_key, file_name) | |
| Creates a subkey under the specified key. | |
| OpenKey (key, sub_key, reserved=0, access=KEY_READ) | |
| Opens the specified key, returning a handle object. | |
| OpenKeyEx (key, sub_key, reserved=0, access=KEY_READ) | |
| Opens the specified key, returning a handle object. | |
| QueryInfoKey (key) | |
| Returns information about a key, as a tuple. | |
| QueryValue (key, sub_key) | |
| Retrieves the unnamed value for a key, as a string. | |
| QueryValueEx (key, value_name) | |
| Retrieves the type and data for a specified value name. | |
| SaveKey (key, file_name) | |
| Saves the specified key, and all its subkeys to the specified file. | |
| SetValue (key, sub_key, type, value) | |
| Associates a value with a specified key. | |
| SetValueEx (key, value_name, reserved, type, value) | |
| Stores data in the value field of an open registry key. | |
| DisableReflectionKey (key) | |
| Disables registry reflection. | |
| EnableReflectionKey (key) | |
| Restores registry reflection for the specified disabled key. | |
| QueryReflectionKey (key) | |
| Determines the reflection state for the specified key. | |
| get_file_info (path_name, string_name) | |
| Extract information from a windows exe file version resource. | |
Variables | |
| long = int | |
| Type long for Python 2 compatibility. | |
| basestring = str | |
| Type basestring for Python 2 compatibility. | |
| str | _LOCALHOST |
| Loopback address. | |
| int | _BUFFER_SIZE |
| Transmission buffer size. | |
| _WIN_DIR | |
| Directory for the windows executables. | |
| _EXESUFFIX | |
| Set the exe suffix for the CPU in use. | |
| _WIN_EXE | |
| Patch to the executable to bridge. | |
| _LISTEN_SOCKET | |
| Socket used for listening for the exe. | |
| _LISTEN_PORT | |
| Semi-random port assigned to the socket by the operating system. | |
| _EXEC_FP | |
| Popen object for the bridge executable. | |
| _CONNECTION_SOCKET | |
| Connection socket. | |
| _CONNECTION_ADDR | |
| Connection socket. | |
Package that implements winreg for Windows Subsystem for Linux.
| wslwinreg.wslapi.CloseKey | ( | hkey | ) |
Closes a previously opened registry key.
The hkey argument specifies a previously opened key.
| hkey | PyHKEY object or None. |
| wslwinreg.wslapi.ConnectRegistry | ( | computer_name, | |
| key ) |
Establishes a connection to a predefined registry handle.
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". If None, the local computer is used. |
| key | Is the predefined handle to connect to. |
| wslwinreg.wslapi.convert_from_windows_path | ( | path_name | ) |
Convert an absolute Windows path to WSL.
If the path is already Linux format, it will be returned unchanged.
| path_name | Absolute Windows pathname |
| wslwinreg.wslapi.convert_to_windows_path | ( | path_name | ) |
Convert a WSL path to windows if needed.
If the path is already Windows format, it will be returned unchanged.
| path_name | Windows or Linux pathname |
| wslwinreg.wslapi.create_string_buffer | ( | temp_string, | |
| is_binary = False ) |
Convert a string into a utf-8 byte stream.
| temp_string | String to convert |
| is_binary | True if the input in binary, not a string. |
| wslwinreg.wslapi.CreateKey | ( | key, | |
| sub_key ) |
Creates or opens the specified key.
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.
| 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. |
| wslwinreg.wslapi.CreateKeyEx | ( | key, | |
| sub_key, | |||
| reserved = 0, | |||
| access = KEY_WRITE ) |
Creates or opens the specified key.
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.
| 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 | Os an integer that specifies an access mask that describes the desired security access for the key. Default is common.KEY_WRITE. |
| wslwinreg.wslapi.DeleteKey | ( | key, | |
| sub_key ) |
Not implemented.
| wslwinreg.wslapi.DeleteKeyEx | ( | key, | |
| sub_key, | |||
| access = KEY_WOW64_64KEY, | |||
| reserved = 0 ) |
Deletes the specified key.
If the method succeeds, the entire key, including all of its values, is removed.
| key | Is an already open key, or any one of the predefined HKEY_* constants. |
| sub_key | Os 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. |
| access | Is an integer that specifies an access mask that describes the desired security access for the key. Default is common.KEY_WOW64_64KEY. |
| reserved | Is a reserved integer, and must be zero. The default is zero. |
| wslwinreg.wslapi.DeleteValue | ( | key, | |
| value ) |
Removes a named value from a registry key.
| key | Is an already open key, or any one of the predefined HKEY_* constants. |
| value | Is a string that identifies the value to remove. |
| wslwinreg.wslapi.DisableReflectionKey | ( | key | ) |
Disables registry reflection.
Disables registry reflection for 32-bit processes running on a 64-bit operating system.
If the key is not on the reflection list, the function succeeds but has no effect. Disabling reflection for a key does not affect reflection of any subkeys.
| key | Is an already open key, or one of the predefined HKEY_* constants. |
| wslwinreg.wslapi.EnableReflectionKey | ( | key | ) |
Restores registry reflection for the specified disabled key.
Restoring reflection for a key does not affect reflection of any subkeys.
| key | Is an already open key, or one of the predefined HKEY_* constants. |
| wslwinreg.wslapi.EnumKey | ( | key, | |
| index ) |
Enumerates subkeys of an open registry key, returning a string.
The function retrieves the name of one subkey each time it is called. It is typically called repeatedly until an OSError exception is raised, indicating no more values are available.
| key | Is an already open key, or any one of the predefined HKEY_* constants. |
| index | Is an integer that identifies the index of the key to retrieve. |
| wslwinreg.wslapi.EnumValue | ( | key, | |
| index ) |
Enumerates values of an open registry key, returning a tuple.
The function retrieves the name of one subkey each time it is called. It is typically called repeatedly, until an OSError exception is raised, indicating no more values.
| Index | Meaning |
|---|---|
| 0 | A string that identifies the value. |
| 1 | An object that holds the value data, and whose type depends on the underlying registry type |
| 2 | An integer that identifies the type of the value data |
| key | Is an already open key, or any one of the predefined HKEY_* constants. |
| index | Is an integer that identifies the index of the value to retrieve. |
| wslwinreg.wslapi.ExpandEnvironmentStrings | ( | str | ) |
Expands environment variables.
Expands environment variable placeholders NAME% in strings like REG_EXPAND_SZ.
| str | String to expand. |
| wslwinreg.wslapi.find_windows_boot_drive | ( | ) |
Using the PATH, determine the boot drive.
This function intentionally doesn't use the registry since it's used to determine where the bridge exe file should be located.
| wslwinreg.wslapi.FlushKey | ( | key | ) |
Writes all the attributes of a key to the registry.
It is not necessary to call FlushKey() to change a key. Registry changes are flushed to disk by the registry using its lazy flusher. Registry changes are also flushed to disk at system shutdown. Unlike CloseKey(), the FlushKey() method returns only when all the data has been written to the registry. An application should only call FlushKey() if it requires absolute certainty that registry changes are on disk.
| key | Is an already open key, or any one of the predefined HKEY_* constants. |
| wslwinreg.wslapi.get_exe_path | ( | ) |
Determine where the bridge exe resides.
Check if the exe is installed, and if not, install it.
This is done because launching an EXE file from the Linux file system is slow. This corrects the issue
| wslwinreg.wslapi.get_file_info | ( | path_name, | |
| string_name ) |
Extract information from a windows exe file version resource.
Given a windows exe file, extract the "StringFileInfo" resource and parse out the data chunk named by string_name.
Full list of resource names: https://docs.microsoft.com/en-us/windows/desktop/menurc/stringfileinfo-block
Examples
| path_name | Name of the windows file. |
| string_name | Name of the data chunk to retrieve |
| wslwinreg.wslapi.get_windows_user | ( | ) |
Determine the name of the user logged into Windows.
Don't use the registry
| wslwinreg.wslapi.LoadKey | ( | key, | |
| sub_key, | |||
| file_name ) |
Creates a subkey under the specified key.
Creates a subkey under the specified key and stores registration information from a specified file into that subkey.
This file must have been created with the SaveKey() function. Under the file allocation table (FAT) file system, the filename may not have an extension.
A call to LoadKey() fails if the calling process does not have the SE_RESTORE_PRIVILEGE privilege.
If key is a handle returned by ConnectRegistry(), then the path specified in fileName is relative to the remote computer.
| key | Is a handle returned by ConnectRegistry() or one of the constants common.HKEY_USERS or common.HKEY_LOCAL_MACHINE. |
| sub_key | Is a string that identifies the sub_key to load |
| file_name | Is the name of the file to load registry data from. |
| wslwinreg.wslapi.OpenKey | ( | key, | |
| sub_key, | |||
| reserved = 0, | |||
| access = KEY_READ ) |
Opens the specified key, returning a handle object.
| key | Is an already open key, or any one of the predefined HKEY_* constants. |
| sub_key | Is a string that identifies the sub_key to open |
| reserved | Is a reserved integer, and must be zero. Default is zero. |
| access | Is an integer that specifies an access mask that describes the desired security access for the key. Default is KEY_READ. |
| wslwinreg.wslapi.OpenKeyEx | ( | key, | |
| sub_key, | |||
| reserved = 0, | |||
| access = KEY_READ ) |
Opens the specified key, returning a handle object.
| key | Is an already open key, or any one of the predefined HKEY_* constants. |
| sub_key | Is a string that identifies the sub_key to open |
| reserved | Is a reserved integer, and must be zero. Default is zero. |
| access | Is an integer that specifies an access mask that describes the desired security access for the key. Default is KEY_READ. |
| wslwinreg.wslapi.QueryInfoKey | ( | key | ) |
Returns information about a key, as a tuple.
| Index | Meaning |
|---|---|
| 0 | An integer giving the number of sub keys this key has. |
| 1 | An integer giving the number of values this key has. |
| 2 | An integer giving when the key was last modified (if available) as 100’s of nanoseconds since Jan 1, 1601. |
| key | Is an already open key, or any one of the predefined HKEY_* constants. |
| wslwinreg.wslapi.QueryReflectionKey | ( | key | ) |
Determines the reflection state for the specified key.
| key | Is an already open key, or any one of the predefined HKEY_* constants. |
| wslwinreg.wslapi.QueryValue | ( | key, | |
| sub_key ) |
Retrieves the unnamed value for a key, as a string.
Values in the registry have name, type, and data components. This method retrieves the data for a key’s first value that has a NULL name. But the underlying API call doesn’t return the type, so always use QueryValueEx() if possible.
| key | Is an already open key, or any one of the predefined HKEY_* constants. |
| sub_key | Is a string that holds the name of the subkey with which the value is associated. If this parameter is None or empty, the function retrieves the value set by the SetValue() method for the key identified by key. |
| wslwinreg.wslapi.QueryValueEx | ( | key, | |
| value_name ) |
Retrieves the type and data for a specified value name.
Retrieves the type and data for a specified value name associated with an open registry key.
| Index | Meaning |
|---|---|
| 0 | The value of the registry item. |
| 1 | An integer giving the registry type for this value. |
| key | Is an already open key, or any one of the predefined HKEY_* constants. |
| value_name | Is a string indicating the value to query. |
| wslwinreg.wslapi.recv_string | ( | convert_to_string = True | ) |
Recieve a string from the socket.
| wslwinreg.wslapi.SaveKey | ( | key, | |
| file_name ) |
Saves the specified key, and all its subkeys to the specified file.
If key represents a key on a remote computer, the path described by file_name is relative to the remote computer. The caller of this method must possess the SeBackupPrivilege security privilege.
This function passes NULL for security_attributes to the API.
| key | Is an already open key, or any one of the predefined HKEY_* constants. |
| file_name | Is the name of the file to save registry data to. This file cannot already exist. If this filename includes an extension, it cannot be used on file allocation table (FAT) file systems by the LoadKey() method. |
| wslwinreg.wslapi.SetValue | ( | key, | |
| sub_key, | |||
| type, | |||
| value ) |
Associates a value with a specified key.
If the key specified by the sub_key parameter does not exist, the SetValue function creates it.
Value lengths are limited by available memory. Long values (more than 2048 bytes) should be stored as files with the filenames stored in the configuration registry. This helps the registry perform efficiently.
The key identified by the key parameter must have been opened with common.KEY_SET_VALUE access.
| key | Is an already open key, or any one of the predefined HKEY_* constants. |
| sub_key | Is a string that names the subkey with which the value is associated. |
| type | is an integer that specifies the type of the data. Currently this must be REG_SZ, meaning only strings are supported. Use the SetValueEx() function for support for other data types. |
| value | Is a string that specifies the new value. |
| wslwinreg.wslapi.SetValueEx | ( | key, | |
| value_name, | |||
| reserved, | |||
| type, | |||
| value ) |
Stores data in the value field of an open registry key.
This method can also set additional value and type information for the specified key. The key identified by the key parameter must have been opened with KEY_SET_VALUE access.
To open the key, use the CreateKeyEx() or OpenKeyEx() methods.
Value lengths are limited by available memory. Long values (more than 2048 bytes) should be stored as files with the filenames stored in the configuration registry. This helps the registry perform efficiently.
| key | Is an already open key, or any one of the predefined HKEY_* constants. |
| value_name | Is a string that names the subkey with which the value is associated. |
| reserved | can be anything – zero is always passed to the API. |
| type | Is an integer that specifies the type of the data. |
| value | Is a string that specifies the new value. |
| wslwinreg.wslapi.test_string | ( | input_string | ) |
Raise an exception if the input is not None or a string.
| input_string | String to test. |
|
protected |
Connection socket.
Connection address.