| 1 |
# Code snippets |
| 2 |
|
| 3 |
## Windows Registry |
| 4 |
|
| 5 |
To open a specific Windows Registry key from a specific Windows Registry file: |
| 6 |
|
| 7 |
```python |
| 8 |
from dfwinreg import registry |
| 9 |
from winreg_kb import collector |
| 10 |
|
| 11 |
filename = 'NTUSER.DAT' |
| 12 |
|
| 13 |
collector_object = collector.WindowsVolumeCollector() |
| 14 |
collector_object.GetWindowsVolumePathSpec(filename) |
| 15 |
|
| 16 |
registry_file_reader = collector.CollectorRegistryFileReader(collector_object) |
| 17 |
win_registry = registry.WinRegistry(registry_file_reader=registry_file_reader) |
| 18 |
``` |
| 19 |
|
| 20 |
## Windows Registry keys |
| 21 |
### Retrieving a key by its path |
| 22 |
|
| 23 |
```python |
| 24 |
key_path = 'HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion' |
| 25 |
|
| 26 |
registry_key = win_registry.GetKeyByPath(key_path) |
| 27 |
``` |
| 28 |
|
| 29 |
## Iterating the subkeys |
| 30 |
|
| 31 |
```python |
| 32 |
for subkey in registry_key.GetSubkeys(): |
| 33 |
print subkey.name |
| 34 |
``` |