Simplified wrapper for the Python winreg module. ๐๏ธ
git(recommended)
git clone https://github.com/kubinka0505/regmgr
cd regmgr/Files
python setup.py installpython -m pip install regmgr -UWarning
Installing this module on non-NT operating systems will raise error.
- โ๏ธ User-friendly
pathlib.Path-alike syntax - โ๏ธ Popular
os-alike function aliases, such as.mkdir(),.getcwd(), etc. - โ๏ธ Registry keys navigation*
- โ๏ธ Variables setting
- โ๏ธ Variables retrieval
- โ๏ธ Variables removal
- โ๏ธ Variables renaming
- โ๏ธ Exporting to
.regfiles - โ๏ธ Subkeys creation
- โ๏ธ Recursive subkeys removal*
- โ๏ธ Valid subkey name casing
- โ Safety ๐ฅถ
* - unstable
Tip
HKEY_CURRENT_USER is the only hive that does not require admin privileges to manage.
Tip
To disable the UAC warning, add the variable named as following to the environment variables listbefore importing module.
Letter case is not important. ๐
Line 22 in 90406c1
Important
Due to the architecture of the registry editor, the relative paths in it's subkey names do not behave as standard directories.
For example in the os module, particulary os.pardir and os.curdir)
In order to get a value from a subkey located in a parent one, either a new RegEntry object must be created or the .relcd() function has to be used.
>>> import regmgr
>>> reg = regmgr.RegEntry(r"HKEY_CURRENT_USER\Facts")
>>>
>>> # Create it
>>> reg.mkdir(exist_ok = True)
>>>
>>> # Create another one
>>> reg.mkdir("I got unusual/unexpected behavior.\..Indeed.")
>>> reg.subkeys(recursive = True)
('I got unusual/unexpected behavior.', 'I got unusual/unexpected behavior.\\..Indeed.')Caution
The .relcd() function does not work with mixed slashes, as it uses os.path.normpath.
If new subkey contains slashes or /../ sequence, creating new RegEntry object is mandatory.
Using them is not reccomended.
>>> import regmgr
>>> reg = regmgr.RegEntry(r"HKCC\Software")
>>>
>>> # Does not work due to `os.path.normpath`
>>> reg.relcd("Do this/that")
>>> reg.path
'HKEY_CURRENT_CONFIG\\Software\\Do this\\that'
>>> # ...instead of "HKCC\Software\Do this/that\"
>>>
>>> # back to "HKCC\Software" then
>>> reg.relcd("../..")
>>>
>>> # Use like this
>>> new_key = r"My key with slashes/../or dots")
>>> reg.mkdir(new_key)
>>> reg = regmgr.RegEntry("\\".join((reg.path, new_key)))
>>> reg.path
'HKEY_CURRENT_CONFIG\\Software\\My key with slashes/../or dots'Get variables from the registry subkey โ๏ธ
>>> import regmgr
>>>
>>> # Create registry object
>>> reg = regmgr.RegEntry(r"HKLM\Software\Microsoft\Windows NT\CurrentVersion")
>>>
>>> print("My system is:", reg["ProductName"])
My system is: Windows 10 HomeCreate new subkey and set new variables โ
>>> import regmgr
>>> reg = regmgr.RegEntry(r"HKCU\Software")
>>> reg.relcd("A custom subkey")
>>>
>>> # Create new subkey
>>> reg.make()
>>>
>>> # Set new values
>>> reg["1st variable"] = "This is a REG_SZ handler"
>>>
>>> reg.set("1st variable", "I can be updated", "sz", exist_ok = True)
>>> reg.set("2nd variable", regmgr.converter.str_to_bytes("some string"), "binary")
>>> reg.set("3rd variable", regmgr.converter.hex_to_str("73 74 72 69 6e 67"), "binary")
>>> reg.set("4th variable", 0x0505, "dword") # Hexadecimal
>>> reg.set("5th variable", 1285, "qword") # Decimal
>>> reg.set("6th variable", ("Each", "word", "is", "a", "line"), "multi_sz")
>>> reg.set("7th variable", "Expandable", "expand_sz")
>>>
>>> # Navigate to parent subkey
>>> reg.relcd("..")Remove a subkey with all of its contents ๐ฎ
>>> import regmgr
>>> reg = regmgr.RegEntry(r"HKEY_CURRENT_USER\Software\A custom subkey")
>>>
>>> # More safe, however `reg.delete_subkeys()` can be executed
>>> current_key = reg.basename
>>> reg.relcd("..")
>>>
>>> reg.delete_subkeys(current_key)Check if subkey exists ๐
>>> import regmgr
>>>
>>> key = r"HKEY_CLASSES_ROOT\.py"
>>>
>>> # Default
>>> regmgr.RegEntry(key).exists()
True
>>>
>>> # Alternative, os-like
>>> regmgr.path.exists(key)
TrueList subkey's... subkeys ๐
>>> import regmgr
>>> reg = regmgr.RegEntry(r"HKEY_USERS\.DEFAULT\Control Panel\International")
>>>
>>> # Basic, iterative
>>> dir(reg)
['Geo', 'User Profile', 'User Profile System Backup']
>>>
>>> # Advanced, iterative
>>> print("\n".join( reg.subkeys(recursive = False, absolute_paths = True) ))
HKEY_USERS\.DEFAULT\Control Panel\International\Geo
HKEY_USERS\.DEFAULT\Control Panel\International\User Profile
HKEY_USERS\.DEFAULT\Control Panel\International\User Profile System Backup
>>>
>>> # Advanced, recursive
>>> reg.subkeys(recursive = True, absolute_paths = False)
('Geo', 'User Profile', 'User Profile\\en-US', 'User Profile System Backup', 'User Profile System Backup\\en-US')List subkey's variables ๐ข
>>> import regmgr
>>> reg = regmgr.RegEntry(r"HKCU\Software\Microsoft\Accessibility")
>>>
>>> # Current
>>> reg.as_dict(recursive = False)
{'CursorColor': [65471, 'REG_DWORD'], 'CursorType': [3, 'REG_DWORD'], 'CursorSize': [3, 'REG_DWORD']}
>>>
>>> # Recursive
>>> reg.as_dict(recursive = True)
{'CursorColor': [65471, 'REG_DWORD'], 'CursorType': [3, 'REG_DWORD'], 'CursorSize': [3, 'REG_DWORD'], 'CursorIndicator': {'IndicatorColor': [16711871, 'REG_DWORD'], 'IndicatorType': [3, 'REG_DWORD']}}Save to .reg file ๐พ
>>> import regmgr
>>> reg = regmgr.RegEntry(r"HKEY_CURRENT_USER\Control Panel\Quick Actions\Control Center")
>>>
>>> # Simple
>>> # Inherits the current key name to current location
>>> # Does not write subkeys without subkeys or/and variables
>>> reg.export()
'C:\\Users\\Admin\\AppData\\Local\\Programs\\Python\\PythonXXX\\Control Center.reg'
>>>
>>> # Advanced
>>> # Custom location with specified filename, though accepts directories only as well
>>> # Editable argument allows writing keys without any subkeys or/and variables
>>> reg.export("~/custom.reg", editable = True)
'C:\\Users\\Admin\\custom.reg'
>>> ...and more ๐
Important
The coincidence of all sorts of names and audio/visual media is coincidental - the author of this particular software is not affiliated nor with Microsoft or its affiliates, and is not responsible for guaranteeing its correct behavior nor the consequences resulting from its improper use.