Skip to main content

Library aimed at working with Windows registry

Project description

WinRegistry

PyPI PyPI

Python package aimed at working with Windows Registry

Installation

Install via PyPI:

pip install winregistry

Usage

import winreg
from winregistry import open_key, open_value

# connect to registry and ensure sub-key
with open_key(
  winreg.HKEY_LOCAL_MACHINE,
  sub_key="SOFTWARE\_REMOVE_ME_",
) as key:
  ...

# also you can connect to registry with string key
with open_key(
  "HKLM\SOFTWARE\_REMOVE_ME_",
) as key:
  ...

# delete key
with open_key(
  winreg.HKEY_LOCAL_MACHINE,
  sub_key="SOFTWARE",
) as key:
  key.delete_key("_REMOVE_ME_")

# create value
with open_key(
  "HKLM\SOFTWARE\_REMOVE_ME_", 
  sub_key_ensure=True, 
  sub_key_access=winreg.KEY_SET_VALUE,
) as key:
    key.set_value("foo", "SZ")

# read value
with open_value(
  "HKLM\SOFTWARE\_REMOVE_ME_", 
  value_name="remove_me",
) as value:
  ...

Usage with Robot Testing Framework

Documentation

https://shpaker.github.io/winregistry/winregistry.robot

Example

*** 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 }
    Create 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 }  Remove me!
    ${ value } =    Read Registry Value     ${ CASE_KEY_NAME }  ${ VALUE_NAME }
    Should Be Equal     ${ value.data }     Remove me!
    Delete Registry Value                   ${ CASE_KEY_NAME }  ${ VALUE_NAME }

Project details


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.1.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

winregistry-2.0.1-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file winregistry-2.0.1.tar.gz.

File metadata

  • Download URL: winregistry-2.0.1.tar.gz
  • Upload date:
  • Size: 6.2 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

Hashes for winregistry-2.0.1.tar.gz
Algorithm Hash digest
SHA256 02931655fb0421b65385990e8472b1f49a43c7c1ff96c2b2ad489e5627ee3363
MD5 6fb0259661d1a0a1b18b5ad37495b5df
BLAKE2b-256 2934a09f8b0458f2082f567f53419da7bc91d1de6887a5596d187623aac8d5a0

See more details on using hashes here.

File details

Details for the file winregistry-2.0.1-py3-none-any.whl.

File metadata

  • Download URL: winregistry-2.0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.9 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

Hashes for winregistry-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6401d65abc2cf52f55896559bfd915a6caf78c6032c8ff2d45f1e0df0592fc27
MD5 2bb606f4629f296c7bf1dd7cc90110d1
BLAKE2b-256 cfb02df03a38beead518e3c8ff88941bd849765f869f4de48fd827b0213cf724

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page