Library aimed at working with Windows registry
Project description
from winregistry import create_key
WinRegistry
Python package aimed at working with Windows Registry
Installation
Install via PyPI:
pip install winregistry
Advances usage
import winreg
from winregistry import open_key
# connect to registry and ensure sub-key
with open_key(
winreg.HKEY_LOCAL_MACHINE,
sub_key="SOFTWARE\_REMOVE_ME_",
sub_key_ensure=True,
) as key:
...
# also you can connect to registry with string key
with open_key(
"HKLM\SOFTWARE\_REMOVE_ME_",
) as key:
...
# create or open sub-key
with open_key(
winreg.HKEY_LOCAL_MACHINE,
sub_key="SOFTWARE",
) as key:
with key.create_key("_REMOVE_ME_"):
...
# delete key
with open_key(
winreg.HKEY_LOCAL_MACHINE,
sub_key="SOFTWARE",
) as key:
key.delete_key("_REMOVE_ME_")
# set value to subkey
with open_key(
winreg.HKEY_LOCAL_MACHINE,
sub_key="SOFTWARE\_REMOVE_ME_",
sub_key_ensure=True,
) as key:
key.set_value(
name="remove_me",
type=winreg.REG_SZ,
value="Remove me!",
)
# read value
with open_key(
winreg.HKEY_LOCAL_MACHINE,
sub_key="SOFTWARE\_REMOVE_ME_",
sub_key_ensure=True,
) as key:
value = key.read_value("remove_me")
# change data of value
with open_key(
winreg.HKEY_LOCAL_MACHINE,
sub_key="SOFTWARE\_REMOVE_ME_",
sub_key_ensure=True,
) as key:
value.data = "Don't forget remove me!"
# delete value in subkey
with open_key(
winreg.HKEY_LOCAL_MACHINE,
sub_key="SOFTWARE\_REMOVE_ME_",
sub_key_ensure=True,
) as key:
value = key.delete_value("remove_me")
Usage with Robot Testing Framework
*** Variables ***
${SUITE_KEY_NAME} HKLM\\SOFTWARE\\_ROBOT_TESTS_
${SHORT_CASE_KEY_NAME} _CASE_KEY_
${CASE_KEY_NAME} ${SUITE_KEY_NAME}\\${SHORT_CASE_KEY_NAME}
${VALUE_NAME} some_testing_value
*** Settings ***
Library Collections
Library winregistry.robot
Suite Setup Create Registry Key ${ SUITE_KEY_NAME }
Suite Teardown Delete Registry Key ${ SUITE_KEY_NAME }
*** Test Cases ***
TEST REGISTRY KEYS
[Teardown] Delete Registry Key ${CASE_KEY_NAME}
${ items } = Get Registry Key Sub Keys ${ SUITE_KEY_NAME }
List Should Not Contain Value ${ items } ${ SHORT_CASE_KEY_NAME }
Registry Key Should Not Exist ${ CASE_KEY_NAME }
Create Registry Key ${ CASE_KEY_NAME }
Registry Key Should Exist ${ CASE_KEY_NAME }
${ items } = Get Registry Key Sub Keys ${ SUITE_KEY_NAME }
List Should Contain Value ${ items } ${ SHORT_CASE_KEY_NAME }
TEST REGISTRY VALUES
[Setup] Create Registry Key ${ CASE_KEY_NAME }
[Teardown] Delete Registry Key ${ CASE_KEY_NAME }
${ items } = Get Registry Key Values Names ${ CASE_KEY_NAME }
List Should Not Contain Value ${ items } ${ VALUE_NAME }
Registry Value Should Not Exist ${ CASE_KEY_NAME } ${ VALUE_NAME }
Set Registry Value ${ CASE_KEY_NAME } ${ VALUE_NAME } SZ
Registry Value Should Exist ${ CASE_KEY_NAME } ${ VALUE_NAME }
${ items } = Get Registry Key Values Names ${ CASE_KEY_NAME }
List Should Contain Value ${ items } ${ VALUE_NAME }
${ value } = Read Registry Value ${ CASE_KEY_NAME } ${ VALUE_NAME }
Should Be Equal ${ value.data } ${ EMPTY }
Set Registry Value ${ CASE_KEY_NAME } ${ VALUE_NAME } SZ foo
${ value } = Read Registry Value ${ CASE_KEY_NAME } ${ VALUE_NAME }
Should Be Equal ${ value.data } foo
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
winregistry-2.0.0a4.tar.gz
(6.1 kB
view details)
Built Distribution
File details
Details for the file winregistry-2.0.0a4.tar.gz
.
File metadata
- Download URL: winregistry-2.0.0a4.tar.gz
- Upload date:
- Size: 6.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.10.15 Linux/6.5.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04a6bdbb2446b5fd48b7c3ddf103e426bb7fdde1d9fbfd09ad21ec6c9eb7bca8 |
|
MD5 | 061fa1e426eb4d521701620ddb12842a |
|
BLAKE2b-256 | 4c9239e83718941695b41ac7fef1de1849d6be13106dc7d8c2cc30173b8d15ea |
File details
Details for the file winregistry-2.0.0a4-py3-none-any.whl
.
File metadata
- Download URL: winregistry-2.0.0a4-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.10.15 Linux/6.5.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6614716d00ce8c7b459ebd926b93a7c50739466890bb35f8b7701bb2a195e34f |
|
MD5 | 976362b41a0e3117da7a69804ff8b1d2 |
|
BLAKE2b-256 | b7e49d66d1429d86682749e6b6263e53f71e2efee17db0cfa87bcc44bdb782cc |