A sane way of working with the Windows registry
Project description
betterwinreg
A sane way of working with the Windows registry.
Getting a RegistryKey instance
To get a RegistryKey
instance, simply do:
from betterwinreg.key import RegistryKey
key = RegistryKey('HKEY_MY_HKEY/Path/To/Key/You/Want')
You can also use backslashes:
key = RegistryKey('HKEY_MY_KEY\\Path\\To\\Key\\You\\Want')
Or, if you don't want to escape every backslash, you can use raw strings:
key = RegistryKey(r'HKEY_MY_KEY\Path\To\Key\You\Want')
Getting values
You can get a specific value by using a dict-like syntax:
my_value = key['Value']
You can also iterate though all the values a key has:
for name, value in key.values().items():
# do some stuff
For example, you would get the wallpaper path by doing:
wallpaper_path = RegistryKey(r'HKEY_CURRENT_USER\Control Panel\Desktop')['WallPaper']
Note that getting a value returns a special object that represents the registry type. You can use it normally, but doing stuff with it will make it a regular instance of the base type.
>>> RegistryKey(r'HKEY_CURRENT_USER\Control Panel\Desktop')['WallPaper']
Sz('D:\\Pictures\\wallpaper.png')
Setting and deleting values
Since registry types are different than Python types, you need to specify what type the registry value will be set to.
from betterwinreg.value import Sz
RegistryKey(r'HKEY_CURRENT_USER\Control Panel\Desktop')['WallPaper'] = Sz(r'D:\Pictures\wallpaper.png')
To delete a value, you can use del
:
del RegistryKey(r'HKEY_CLASSES_ROOT\Directory\Shell\git_shell')['WallPaper']
Navigating through the registry
The main ways to move through the registry are using subkeys()
and parent
, and concatenating in a Path-like way.
>>> RegistryKey(r'HKEY_CURRENT_USER\Control Panel\Desktop').parent
RegistryKey('HKEY_CURRENT_USER\\Control Panel')
>>> RegistryKey(r'HKEY_CURRENT_USER\Control Panel\Desktop').subkeys()
[RegistryKey('HKEY_CURRENT_USER\\Control Panel\\Desktop\\Colors'), RegistryKey('HKEY_CURRENT_USER\\Control Panel\\Desktop\\WindowMetrics'), RegistryKey('HKEY_CURRENT_USER\\Control Panel\\Desktop\\MuiCached')]
You can also join RegistryKey
s in a Path
-like manner:
>>> RegistryKey(r'HKEY_CURRENT_USER\Control Panel') / 'Desktop'
RegistryKey('HKEY_CURRENT_USER\\Control Panel\\Desktop')
Notes
Only tested on Windows 10 64-bit. It won't work on 32-bit, because of some incompatible API calls (e.g. RegDeleteKeyEx
).
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
Built Distribution
File details
Details for the file betterwinreg-1.0.0.tar.gz
.
File metadata
- Download URL: betterwinreg-1.0.0.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 23e32909938687ac757f27d84367b07f13b890de5c1b79a5d8fb2acb40dadc6c |
|
MD5 | d9ebf4308e2da0188f9213ba5658b313 |
|
BLAKE2b-256 | a59c59e37e7a602435dc1df50c6b6538c411a8a6c98dfdd3f2d5d94edfa038d3 |
File details
Details for the file betterwinreg-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: betterwinreg-1.0.0-py3-none-any.whl
- Upload date:
- Size: 18.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.37.0 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 73fdc8b33e4ea80a6d661933fec9ca03973ce04c36040675cbdf6c3716690a5e |
|
MD5 | edcce00db51d318c9959591378b409f2 |
|
BLAKE2b-256 | 393483078fcde6e19334edd0989404549fb6150fab439504a038c170efb4362d |