Use the _winreg module to obtain the value of a registry key. Args: key: The registry key. value: The particular registry value to read. Return: contents of the registry key's value, or None on failure. Throws ImportError if winreg is unavailable.
(key, value)
| 218 | |
| 219 | |
| 220 | def _RegistryGetValueUsingWinReg(key, value): |
| 221 | """Use the _winreg module to obtain the value of a registry key. |
| 222 | |
| 223 | Args: |
| 224 | key: The registry key. |
| 225 | value: The particular registry value to read. |
| 226 | Return: |
| 227 | contents of the registry key's value, or None on failure. Throws |
| 228 | ImportError if winreg is unavailable. |
| 229 | """ |
| 230 | from winreg import HKEY_LOCAL_MACHINE, OpenKey, QueryValueEx # noqa: PLC0415 |
| 231 | |
| 232 | try: |
| 233 | root, subkey = key.split("\\", 1) |
| 234 | assert root == "HKLM" # Only need HKLM for now. |
| 235 | with OpenKey(HKEY_LOCAL_MACHINE, subkey) as hkey: |
| 236 | return QueryValueEx(hkey, value)[0] |
| 237 | except OSError: |
| 238 | return None |
| 239 | |
| 240 | |
| 241 | def _RegistryGetValue(key, value): |
no test coverage detected