Skip to content

Registry Value

RegistryValue

Bases: BaseModel

Represents a registry value.

export_reg

export_reg() -> str

Export the registry value as a .reg file format.

Example
"MUIVerb"="Convert mp4..."

Returns:

Type Description
str

The .reg file line representing the registry value.

References
Source code in context_menu_toolkit/registry/registry_structs/registry_value.py
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
def export_reg(self) -> str:
    """Export the registry value as a .reg file format.

    Example:
        ```
        "MUIVerb"="Convert mp4..."
        ```

    Returns:
        The .reg file line representing the registry value.

    References:
        [^1]: <https://support.microsoft.com/en-us/topic/how-to-add-modify-or-delete-registry-subkeys-and-values-by-using-a-reg-file-9c7f37cf-a5e9-e1cd-c4fa-2a26218a1a23>
    """
    if self.type is DataType.REG_SZ:
        data_str = json.dumps(self.data)  # escapes "\" and '"'
    elif self.type is DataType.REG_DWORD:
        data_str = f"dword:{self.data}"
    else:
        raise NotImplementedError(f"registry data type not supported: {self.type}")

    if self.name == "":
        return f"@={data_str}"
    return f'"{self.name}"={data_str}'