bitranox/lib_registry

View on GitHub
lib_registry.ipynb

Summary

Maintainability
Test Coverage
{"cells":[{"metadata":{"pycharm":{"name":"#%%\n"},"trusted":true,"scrolled":false},"cell_type":"code","source":"# update pip and setuptools\nimport sys\n!{sys.executable} -m pip install --upgrade pip\n!{sys.executable} -m pip install --upgrade setuptools\n\n# install lib_registry from pypi\n!{sys.executable} -m pip install --upgrade lib_registry\n\n# install lib_registry from github\n!{sys.executable} -m pip install --upgrade git+https://github.com/bitranox/lib_registry.git","execution_count":null,"outputs":[]},{"metadata":{"pycharm":{"name":"#%%\n"},"trusted":true},"cell_type":"code","source":"# please be noted that the lib_registry interface will change (a lot) in the future, to offer pathlib-like\n# behaviour, as well as context managers, etc.\n\n# this version is fully functional however and allows to read / write / query the windows registry\n# here a few examples !\n\n# lib_registry is using fake_winreg to simulate a windows registry on linux, so this is possible here on jupyter.\nfrom lib_registry import *\nregistry=Registry()","execution_count":null,"outputs":[]},{"metadata":{"pycharm":{"name":"#%%\n"},"trusted":true},"cell_type":"code","source":"# query values - there are only a few values set in the fake registry You can query here.\n# on Your windows machine of course You can query all values You have permission for.\nregistry.get_value(key='HKLM\\\\SOFTWARE\\\\Microsoft\\\\Windows NT\\\\CurrentVersion', value_name='CurrentBuild')","execution_count":null,"outputs":[]},{"metadata":{"pycharm":{"name":"#%%\n"},"trusted":true},"cell_type":"code","source":"# all subkeys, values, etc use generator objects\nregistry.subkeys(winreg.HKEY_USERS)","execution_count":null,"outputs":[]},{"metadata":{"pycharm":{"name":"#%%\n"},"trusted":true},"cell_type":"code","source":"# so lets make a list of all subkeys of HKEY_USERS\nlist(registry.subkeys(winreg.HKEY_USERS))","execution_count":null,"outputs":[]},{"metadata":{"pycharm":{"name":"#%%\n"},"trusted":true},"cell_type":"code","source":"# create a key - pathlib like options (in preparation to pathlib-like behaviour)\ntestkey='HKCU\\\\Software\\\\lib_registry_test'\nreg_handle = registry.create_key(testkey, exist_ok=True, parents=True)","execution_count":null,"outputs":[]},{"metadata":{"pycharm":{"name":"#%%\n"},"trusted":true},"cell_type":"code","source":"# set a value, REG_TYPE can be given or is automatically set\nbinary_test_value=(chr(128512) * 10).encode('utf-8')\nregistry.set_value(testkey, value_name='test_string', value='HAM')\nregistry.set_value(testkey, value_name='test_multi_string', value=['HAM', 'SPAM'])\nregistry.set_value(testkey, value_name='test_int', value=42)\nregistry.set_value(testkey, value_name='test_binary', value=binary_test_value)\nregistry.set_value(testkey, value_name='test_none', value=None)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# get a string value from the Registry\nregistry.get_value(testkey, value_name='test_string')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# get a multi-string value from the Registry\nregistry.get_value(testkey, value_name='test_multi_string')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# get a int value from the Registry\nregistry.get_value(testkey, value_name='test_int')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# get a binary value from the Registry\nregistry.get_value(testkey, value_name='test_binary')","execution_count":null,"outputs":[]},{"metadata":{"pycharm":{"name":"#%%\n"},"trusted":true},"cell_type":"code","source":"# get a None value from the Registry\nstr(registry.get_value(testkey, value_name='test_none'))","execution_count":null,"outputs":[]},{"metadata":{"pycharm":{"name":"#%%\n"},"trusted":true},"cell_type":"code","source":"# delete a value from the registry\nregistry.delete_value(testkey, value_name='test_string')","execution_count":null,"outputs":[]},{"metadata":{"pycharm":{"name":"#%%\n"},"trusted":true},"cell_type":"code","source":"# delete a key from the registry\nregistry.delete_key(testkey)","execution_count":null,"outputs":[]},{"metadata":{"pycharm":{"name":"#%%\n"},"trusted":true},"cell_type":"code","source":"# function to get SID's (Secure ID)\nlist(registry.sids())\n","execution_count":null,"outputs":[]},{"metadata":{"pycharm":{"name":"#%%\n"},"trusted":true},"cell_type":"code","source":"# function to get the username from a SID\nfor sid in registry.sids():\n    print(registry.username_from_sid(sid))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"metadata":{"language_info":{"name":"python","version":"3.10.11","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kernelspec":{"name":"python3","display_name":"Python 3 (ipykernel)","language":"python"}},"nbformat":4,"nbformat_minor":4}