Path: /utilities/util_modify_registry.py
This module provides utility functions for reading, writing, creating, and deleting Windows Registry keys and values, handling hive resolution and WOW64 access flags transparently.
Set application or system configuration by writing values to specific registry hives and key paths.
Clean up registry entries by deleting values or entire keys during uninstallation or maintenance tasks.
Python’s built-in winreg module for registry access.
Raven Development Team’s util_logger for structured logging and util_error_popup for error reporting.
Parameter | Type | Description | Default |
---|---|---|---|
hive | Union[str, int] | Registry hive identifier (e.g. "HKLM", "HKEY_CURRENT_USER") | N/A |
key_path | str | Path of the registry key under the hive | N/A |
name | str | Name of the registry value to operate on | N/A |
value | Any | Data to set for the registry value (int, str, bytes) | N/A |
value_type | Optional[int] | Explicit registry value type (e.g. winreg.REG_DWORD). If omitted, inferred from value. | Inferred |
python util_modify_registry.py --hive HKLM --key_path "SOFTWARE\\MyApp" --name "ExampleValue" --value 42
Each operation first resolves the hive name or constant to a winreg hive handle and computes access flags including KEY_WOW64_64KEY if available. set_value creates or opens the key with write access and writes the specified value and type. get_value reads a value, returning None if not found. delete_value and delete_key remove entries, handling both modern and legacy API calls for cross-version compatibility. All operations log successes and use a UI popup for fatal errors.
Operations are wrapped in try/except blocks. On failure, an exception is logged via logger.exception, a modal error dialog is shown via show_error_popup (terminating the process if continuation is not allowed), and the exception is re-raised to surface the error to calling code.
Modifying the Windows Registry requires appropriate permissions (often Administrator). Callers should ensure elevation (e.g., via util_admin_check.ensure_admin) before invoking write operations. Inputs are passed directly to winreg APIs; callers must validate or sanitize dynamic paths and names to avoid unintended modifications.
Uses the Raven Development Team’s util_logger at various levels:
Unit tests can mock winreg functions to simulate registry behavior. For manual validation, run set_value and get_value in an isolated test hive path and verify changes with regedit or PowerShell.
Author: Raven Development Team